【问题标题】:R ggplot2 axis title troubleR ggplot2 轴标题麻烦
【发布时间】:2013-04-10 22:38:33
【问题描述】:

我对 ggplot 比较陌生。在尝试调整轴标题的主题参数时,我遇到了一些麻烦。具体来说,我想更改字体系列,加粗文本,并稍微向下移动 x 轴标题。我尝试了以下代码 - 我没有收到错误,但图表中没有任何变化。任何想法我做错了什么?我最担心的是用 vjust 将标题向下移动,现在它离我需要的刻度标签太近了。谢谢!

ggplot(Car_data, aes(x=Yearyear, y= Total_cars)) +
geom_line(aes(group=1), colour="#56B4E9", size = 1.5) +
geom_errorbar(aes(ymin= (Mean_Total_Cars - SE_Total_Cars), ymax= (Mean_Total_Cars +    SE_Total_Cars)), width=.2, colour= "black") +
geom_point(stat = "identity", colour="gray40", size=5, shape= 18) + geom_point(stat =    "identity", colour="#56B4E9", size=3, shape= 18) +
theme(axis.title.x = element_text(color = "black", size = 9, family = "Arial", face =  "bold", vjust= 1)) +
theme(axis.title.y = element_text(color = "black", size = 9, family = "Arial", face = "bold")) +
theme(axis.text.x = element_text(color = "black", size = 9, family = "Arial", face = "bold")) +
theme(axis.text.y = element_text(color = "black", size = 9, family = "Arial", face = "bold")) +
ylab("Mean # Cars") +
xlab("Year")

【问题讨论】:

  • 您在ylab(expression(paste("Mean # Cars")"))) 中缺少, 和结束"
  • 哎呀,谢谢-我实际上是在尝试简化发布的更复杂的表达式,但很草率。具体来说,是 element_text 选项不起作用。网格线的标签、选项等正在按应有的方式显示。
  • 只更改标题?

标签: r ggplot2


【解决方案1】:

您可以将vjust 设置为负数。您可能希望更改plot.marginpanel.margin 以留出足够的空间

例如没有任何费用

ggplot(mtcars, aes(x=mpg,y=am)) + geom_point() 

vjust = -1plot.margin 的底部边距略有增加

ggplot(mtcars, aes(x=mpg,y=am)) + geom_point()  + 
  theme(axis.title.x = element_text(size=14, face = 'bold', vjust = -1), 
        plot.margin = unit(c(1,1,1,0.5), 'lines'))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多