我想绘制两行字符在与ggplot2
相同的情节。我知道你可以用grid.arrange来做,但我肯定会在代码中丢失一些东西。ggplot2:为什么grid.arrange不工作?
这里是我的数据,在这里我想绘制了时间和速率
motor;trace;time;rate
monetDBIE;1m;5448;183553
monetDBIE;2m;8734;228990
monetDBIE;5m;19468;256831
Jena;1m;8273;120875
Jena;2m;16916;118231
Jena;5m;44776;111666
PGSQLIE;1m;6859;145793
PGSQLIE;2m;13106;152601
PGSQLIE;5m;32793;152471
这里是我的代码
require("ggplot2")
require("gridExtra")
w <- read.csv(file="loading.csv", head=TRUE, sep=";")
# first plot
p <- ggplot(data=w, aes(x=trace, y=time, colour=motor, shape=motor))
p <- p + geom_point(size=4)
p <- p + geom_line(size=1,aes(group=motor))
p <- p + geom_text(aes(label=time), hjust=-0.2, vjust=1)
p <- p + ggtitle("Triplestores ")
p <- p + labs(x = "Traces", y = "Temps (ms)")
p <- p + theme_bw()
# second plot
p2 <- ggplot(data=w, aes(x=trace, y=rate, colour=motor, shape=motor))
p2 <- p2 + labs(x = "Traces", y = "débit de chargement (triplets/s)")
p2 <- p2 + geom_point(size=4)
p2 <- p2 + geom_line(size=1,aes(group=motor))
p2 <- p2 + geom_text(aes(label=rate), hjust=-0.2, vjust=1)
p2 <- p2 + theme_bw()
grid.arrange(p, p2, nrow=2, ncol=1)
ggsave(file="loading.pdf")
但不幸的是我仍然只得到一个字符P2看到的画面
为什么?
您的回答我不清楚。什么是'p1','factor(cyl)','mtcars'? – 2015-04-02 16:06:37
'p1'和'p2'是两个任意的ggplot对象。什么是原始问题 - 你想在pdf中使用两个网格布置的图吗?也许我没有找到你.. – lukeA 2015-04-02 16:09:38