我想將子文本(一個textGrob
)添加到grid
Viewport
- 這可能嗎?將子文本添加到視口
我想通了如何子文本添加到一個圖表:
require(ggplot2)
require(gridExtra)
# make the data
timeSeries <- data.frame(date = seq(as.Date("2001-01-01"), as.Date("2012-01-01"), by = "mon"),
value = 1:133 + rnorm(133, 0, 10)
)
# make the ggplots
gpLine <- ggplot(timeSeries, aes(x = date, y = value)) +
geom_line()
gpBar <- ggplot(timeSeries, aes(x = date, y = value)) +
geom_bar(stat = 'identity')
# ggplot + subtext
grid.arrange(gpBar, sub = textGrob("why is this at the bottom?"))
,我還可以使用grid
Viewport
# two plots, one view
vplayout <- function(x,y) viewport(layout.pos.row = x, layout.pos.col = y)
pushViewport(viewport(layout = grid.layout(3,1)))
print(gpLine, vp = vplayout(1:2, 1))
print(gpBar, vp = vplayout(3, 1))
兩個圖表粘在一起......但我不知道如何將文本添加到生成的視口的底部。
Grid
是如此完整的,我敢肯定有必須一種方式,但它是隱藏在我身上。
+1,感謝 - 現在的文字是中期的情節。我可能會完全愚蠢,但是我怎樣才能把它放到底部,因爲'grid.arrange'是用'sub'調用的呢? – ricardo 2013-05-02 11:12:57
只需調整x和y值。在整個繪圖區域中x = y = 0.5是死點。 – 2013-05-02 11:21:31
upViewport一般是優於彈出 – baptiste 2013-05-02 11:51:07