首页 文章

R ggplot2轴 Headers 麻烦

提问于
浏览
1

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

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

1 回答

  • 1

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

    例如,没有任何chages

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

    enter image description here

    并且 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'))
    

    enter image description here

相关问题