řGGPLOT2中心对齐多行标题(R ggplot2 center align a multi-li

2019-08-31 10:22发布

如果我有一个标题,进入

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

有没有什么办法可以让每一行居中对齐,而不是左对齐的中心呢?

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

给我短信的中心,但左对齐。

Answer 1:

将这项工作对你来说,

# 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))

遗憾的情节标题错别字...



文章来源: R ggplot2 center align a multi-line title
标签: r ggplot2