R ggplot2中心对齐多行标题

时间:2013-04-18 04:22:36

标签: r ggplot2

如果我有一个标题

... +
ggtitle('Something\nSomething Else\nSomething Else')

有什么办法可以让每条线对齐居中而不是左对齐?

...+
theme(plot.title=element_text(hjust=0.5))

在中间给我文字,但左对齐。

1 个答案:

答案 0 :(得分:38)

这对你有用吗,

# install.packages("ggplot2", dependencies = TRUE)
require(ggplot2)

DF <- data.frame(x = rnorm(400))
m <- ggplot(DF, aes(x = x)) + geom_histogram()
m + labs(title = "Vehicle \n Weight-Gas \n Mileage Relationship \n 
                 and some really long so that you can seee it's centered") + 
     theme(plot.title = element_text(hjust = 0.5))

enter image description here

抱怨情节标题中的错别字......