R ggplot2中心对齐一个多行标题 [英] R ggplot2 center align a multi-line title
本文介绍了R ggplot2中心对齐一个多行标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个标题
... +
ggtitle('Something \\\
Something Else \ nSomething Else')
有没有什么办法可以让每条线对齐而不是左对齐align in the center?
... +
theme(plot.title = element_text(hjust = 0.5))
给我中间的文字,但左对齐。
#install.packages(class =h2_lin>解决方案
ggplot2,依赖性= TRUE)
require(ggplot2)
DF < - data.frame(x = rnorm(400))
m < - ggplot aes(x = x))+ geom_histogram()
m + labs(title =Vehicle \\\
Weight-Gas \\\
Mileage Relationship \
,有些非常长,所以您可以看到它)+
主题(plot.title = element_text(hjust = 0.5))
对于剧情标题中的错别字,抱歉...
If I have a title that goes
... +
ggtitle('Something\nSomething Else\nSomething Else')
Is there any way I can get each line to center align rather than left align in the center?
...+
theme(plot.title=element_text(hjust=0.5))
gives me text in the center, but left aligned.
解决方案
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))
sorry about the typos in the plot title …
这篇关于R ggplot2中心对齐一个多行标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文