1

我对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")
4

1 回答 1

1

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

例如,没有任何费用

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

在此处输入图像描述

并在vjust = -1底部plot.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'))

在此处输入图像描述

于 2013-04-11T06:30:05.383 回答