23

如果我有一个标题

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

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

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

在中心给我文本,但左对齐。

4

1 回答 1

46

would this work for you,

# 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

sorry about the typos in the plot title …</p>

于 2013-04-18T04:41:28.583 回答