将子文本添加到视口 [英] Add sub text to viewport
本文介绍了将子文本添加到视口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在grid
Viewport
上添加子文本(a textGrob
)-这可能吗?
I would like to add sub text (a textGrob
) to a grid
Viewport
-- is this possible?
我已经弄清楚了如何在单个图表中添加子文本:
I have figured out how to add sub text to a single chart:
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
... And i can stick the two charts together using a 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))
...但是我不知道如何在结果视口的底部添加文本.
... but i cannot figure out how to add text to the bottom of the resulting viewport.
Grid
已经完成了,所以我确定必须有一种方法,但是它对我来说是隐藏的.
Grid
is so complete, i'm sure there must be a way, but it's hidden to me.
推荐答案
您非常亲密:
popViewport() # brings you to the top viewport for the whole plotting area
grid.text("Hello Vicar", x = unit(0.5, "npc"), y = unit(0.25, "npc"))
完成上述所有命令后.
这篇关于将子文本添加到视口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文