Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the default ggplot2 plot margins?

Tags:

I cannot find information on this anywhere. I know how to set them but want to know the defaults (top, right, bottom, and left) so its less of a guessing game when setting margins for a plot.

like image 718
CCurtis Avatar asked Aug 21 '15 18:08

CCurtis


People also ask

What are the default plot margins in R?

To visualize how R creates plot margins, look at margin Figure 11.20. You can adjust the size of the margins by specifying a margin parameter using the syntax par(mar = c(bottom, left, top, right)) , where the arguments bottom , left … are the size of the margins. The default value for mar is c(5.1, 4.1, 4.1, 2.1).

How do I set margins in ggplot2?

In order to modify the plot margins set the margin function inside the plot. margin component of the theme function. The margins are measured with points ( "pt" ), but you can use other unit measure in the unit argument, like centimeters.


1 Answers

For plot margins as well as other parameters, the default values are that of theme_grey:

theme_grey()$plot.margin [1] 5.5pt 5.5pt 5.5pt 5.5pt 

However, the default theme might change in the future, and you can set a different one (with theme_set()) so a more robust way would be to use theme_get() which returns the current theme (@r2evans comment)

theme_get()$plot.margin  
like image 157
scoa Avatar answered Sep 19 '22 21:09

scoa