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 custom the background of your ggplot2 plots. More generally, the R graph gallery proposes 3 pages dedicated to the layout customisation: one concerning axis, one concerning legends, and this one concerning background.

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 awesome ggplot2 documentation for more information.

We start with this really basic plot relying on the mtcars dataset with a default background:

 

 

 

 

 

You can easily color the background. There are 2 main areas: plot background (here in green) and panel background (here in red)

 

 

Then you can custom the grid. There are 2 types of grid: major and minor ones. To custom them, you can use the usual arguments of the element_line function. Note that you can apply the modifications to the X axis or the Y axis only.


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

[mediatagger]


Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz