In ggplot2
版本 0.9 更改了绘图标题的对齐方式。在 v0.8.9 中,对齐是相对于绘图窗口的,而在 v0.9 中,对齐是相对于绘图网格的。
现在,虽然我基本上同意这是理想的行为,但我经常有很长的情节标题。
问题:有没有办法将绘图标题与绘图窗口而不是绘图网格对齐?
我正在寻找一种可以自动对齐绘图的解决方案。换句话说,使用手动对齐hjust
对我来说不起作用(我在每个项目的数百个地块上运行这个)。
使用过的任何解决方案grid
直接也可以接受。
一些示例代码和绘图:(注意标题如何在窗口右侧被截断)。
dat <- data.frame(
text = c(
"It made me feel very positive to brand X",
"It was clear and easy to understand",
"I didn't like it al all"),
value=runif(3)
)
library(ggplot2)
ggplot(dat, aes(text, value)) +
geom_bar(stat="identity") +
coord_flip() +
opts(title="Thinking about the ad that you've just seen, do you agree with the following statements? I agree that...") +
theme_bw(16)
在 ggplot2 0.9 中,您可以轻松更改布局。
p <- ggplot(dat, aes(text, value)) +
geom_bar(stat="identity") +
coord_flip() +
opts(title="Thinking about the ad that you've just seen,\ndo you agree with the following statements?\nI agree that...") +
theme_bw(16)
gt <- ggplot_gtable(ggplot_build(p))
gt$layout[which(gt$layout$name == "title"), c("l", "r")] <- c(1, max(gt$layout$r))
grid::grid.draw(gt)
也许,在未来的版本中,ggplot2 将提供一致的接口来调整布局。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)