这是代码:
require(ggplot2)
require(grid)
# pdf("a.pdf")
png('a.png')
a <- qplot(date, unemploy, data = economics, geom = "line") + opts(title='A')
b <- qplot(uempmed, unemploy, data = economics) + geom_smooth(se = F) + opts(title='B')
c <- qplot(uempmed, unemploy, data = economics, geom="path") + opts(title='C')
grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 2)))
vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
print(a, vp = vplayout(1, 1:2))
print(b, vp = vplayout(2, 1))
print(c, vp = vplayout(2, 2))
dev.off()
结果:
虽然这是我想要的,即将标题放置在 y 轴顶部附近:
您正在寻找的是theme(plot.title = element_text(hjust = 0))
。例如,使用最新版本的 ggplot2 和theme
代替opts
we have
a <- qplot(date, unemploy, data = economics, geom = "line") + ggtitle("A") +
theme(plot.title = element_text(hjust = 0))
或者,与opts
a <- qplot(date, unemploy, data = economics, geom = "line") +
opts(title = "A", plot.title = element_text(hjust = 0))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)