我想将子文本 (a textGrob
) 添加到 a 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
如此完整,我敢肯定一定有办法,但它对我来说是隐藏的。