R ggplot2 轴标题麻烦

R ggplot2 axis title trouble

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

1
2
3
4
5
6
7
8
9
10
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")


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

例如没有任何费用

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

enter

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

1
2
3
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