x-axis labels overlap - want to rotate labels 45º

I'm using the code from this post

with my own data. However, my variable names are longer than those in mtcars. Using that code, how can I rotate the labels on the x-axis 45º to keep them from overlapping?

Advice and suggestions are welcome.

Jason the #rstatsnewbie

You can use the theme() function of ggplot.

DF <- data.frame(L = c("LongLabelAAA", "LongLabelBBB", "LongLabelCCC"),
                 Y = 1:3)
ggplot(DF, aes(L, Y)) + geom_point() +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1))

Created on 2020-04-29 by the reprex package (v0.3.0)

1 Like

Another option as of ggplot2 version 3.3.0 is to stagger the labels:

library(vcd)  # For Baseball data frame

ggplot(Baseball, aes(team86, error86)) + 
  geom_point() +



Both of these are excellent!
I really like the second option!
Thank you.
By any chance do you know what "theme_classic()" is and/or does?

Also, would you (or anyone) know how to highlight cells with significant p-values in this code?

Jason the #rstatsnewbie

You can add + theme_classic() to your ggplot to see what it does. ggplot has several built-in "themes" that customize the overall look of the plot in various ways. The default theme is theme_grey(). You can change this for all future plots by running, for example:


To see available themes in ggplot, see the help for any theme. For example, run ?theme_classic(). The help page that opens will list all of the available themes. The ggthemes package has more, and you can of course create your own.

To tweak any theme, add a theme() statement to a ggplot after setting the overall theme. For example:

ggplot(mtcars, aes(mpg, hp)) +
  geom_point() +
  theme_classic() +

See here and here for web versions of theme help files.

Here are some examples of how ggplots look with various themes.

1 Like

Thank you.
This helps a lot!
I will definitely follow up on your suggestions.

I am sure more questions will come soon enough. :smile::rofl:

~ Jason the #rstatsnewbie

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.