1
votes

I'm relatively new to ggplot. In trying to adjust theme parameters for the axis titles I am running into some trouble. Specifically, I want to change font family, bold the text, and move the x axis title down slightly. I've tried the following code- I don't get an error but nothing in the graph changes. Any ideas what I'm doing wrong? My biggest concern is moving the title down with vjust, right now it's just too close to the tick labels for what I need. Thanks!

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
You are missing a , and a closing " in ylab(expression(paste("Mean # Cars")"))) - mnel
Oops, thanks- I actually was trying to simplify a more complicated expression for the posting and was sloppy. Specifically, it's the element_text options that aren't working. The labels, options for the gridlines, etc. are showing up as they should. - Jean S.
change vjust for the title? - mnel

1 Answers

1
votes

You can set vjust to be negative. You may wish to change plot.margin or panel.margin to allow for sufficient space

eg without any chages

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

enter image description here

and with vjust = -1 and plot.margin increased slightly on the bottom 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