上下文
我想用相同的圖例在同一頁上繪製兩個ggplot2。 http://code.google.com/p/gridextra/wiki/arrangeGrob敘述,如何做到這一點。這已經很好看了。但是......在我的例子中,我有兩個具有相同x軸和不同y軸的圖。當y軸的範圍至少比另一個繪圖高10倍(例如10000而不是1000)時,ggplot2(或者網格?)不能校正繪圖(見下面的輸出)。將多個ggplot2圖與網格對齊
問題
如何我也對準情節的左側,使用兩個不同的y軸?
示例代碼
x = c(1, 2)
y = c(10, 1000)
data1 = data.frame(x,y)
p1 <- ggplot(data1) + aes(x=x, y=y, colour=x) + geom_line()
y = c(10, 10000)
data2 = data.frame(x,y)
p2 <- ggplot(data2) + aes(x=x, y=y, colour=x) + geom_line()
# Source: http://code.google.com/p/gridextra/wiki/arrangeGrob
leg <- ggplotGrob(p1 + opts(keep="legend_box"))
legend=gTree(children=gList(leg), cl="legendGrob")
widthDetails.legendGrob <- function(x) unit(3, "cm")
grid.arrange(
p1 + opts(legend.position="none"),
p2 + opts(legend.position="none"),
legend=legend, main ="", left = "")
參見:http://stackoverflow.com/questions/13294952/left-align-two-g raph-edges-ggplot/13295880#13295880? –