Get Default ggplot2 Plot Margins in R (Example)

 

This article illustrates how to find the default ggplot2 plot margins in the R programming language.

Table of contents:

It’s time to dive into the example.

 

Example: Get Default ggplot2 Plot Margins Using theme_get() Function

The following R syntax illustrates how to return the default area margins of a graphic created by the ggplot2 package.

To be able to use the functions of the ggplot2 package, we first have to install and load ggplot2.

install.packages("ggplot2")    # Install & load ggplot2 package
library("ggplot2")

Next, we can use the theme_get function to return the default margins of a ggplot2 graph:

theme_get()$plot.margin        # Print default plot margins
# [1] 5.5points 5.5points 5.5points 5.5points

As you can see based on the previous output of the RStudio console, the default area margins of a ggplot2 plot are 5.5points on all sides of the plot, i.e. the bottom, the left side, the top, and on the right side.

 

Video & Further Resources

Some time ago, I have published a video on my YouTube channel, which illustrates the R syntax of this post. You can find the video below.

 

 

Furthermore, you may read some of the other articles on my website.

 

In summary: This article has explained how to get the default area margins of a ggplot2 graphic in R. If you have further questions, tell me about it in the comments section below.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

The maximum upload file size: 2 MB. You can upload: image. Drop file here

Top