Share the Gallery !Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInEmail this to someone

 

 

This page aims to provide useful R code to customise the axis of your ggplot2 plots. More generally, the R graph gallery proposes 3 pages dedicated to the layout customisation: one concerning legends, one concerning background, and this one concerning axis.

Here we want to modify non-data components, and it is often done trough the theme() command. This page is strongly inspired from the help page of ggplot2 (?theme). Also, do not hesitate to visit the very strong ggplot2 documentation for more information.

We start with this very basic plot relying on the mtcars dataset.

 

 

 

Now we can start the customisation. Let’s add a title, modify x-axis name and expand x-axis limits:

 

If we want to customise the axis names, we need to use axis.title inside a theme element. Note that you can apply the modification on both axes or on one only, using .x or .y:

 

 

 

 

To change the axis text, we’ll use the axis.text argument.

The 3 last examples show how to 1/ modify ticks 2/ modify axis lines 3/ combine all the possible customization in the same plot.


Not what you are looking for ? Make a new search !


Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of