我想繪製兩行字符在與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