【发布时间】:2017-09-05 13:43:46
【问题描述】:
我的数据如下所示:
height <- c(1,2,3,4,2,4,6,8)
weight <- c(12,13,14,15,22,23,24,25)
person <- c("Jack","Jim","Jill","Tess","Jack","Jim","Jill","Tess")
set <- c(1,1,1,1,2,2,2,2)
dat <- data.frame(set,person,height,weight)
我正在尝试使用 plotrix 包中的 twoord.plot 函数绘制具有相同 x 轴(人)和 2 个不同 y 轴(体重和身高)的图形。
但是,我不知道如何像 ggplot2 中那样刻面。
例如,如果我的绘图可以覆盖在 ggplot2 中,我的代码将如下所示:
ggplot(data = dat, aes(x = person, y = weight)) +
geom_point(color = "red") + facet_wrap(~set, scales="free")
#And similarly have the height on the other axis.
关于如何在 twoord.plot() 中实现这一点的任何想法?
【问题讨论】:
-
从the documentation看来这个函数没有使用facets。
-
我知道。但我想知道是否有什么“技巧”可以用来解决这个问题?
-
没有“技巧”。您必须对数据进行子集化,生成单独的图并使用例如
par(mfrow = ...)或panes 组合它们。但我想知道你为什么不简单地使用ggplot2。 -
因为 ggplot2 给我带来了很多麻烦。我尝试使用 sec_axis(),但似乎没有人知道正确的解决方案。见这里:stackoverflow.com/questions/46045258/…
标签: r plot multiple-axes