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 #  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.
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
If you accept this notice, your choice will be saved and the page will refresh.
Furthermore, you may read some of the other articles on my website.
- Draw Time Series Plot with Events Using ggplot2 Package
- Add Polynomial Regression Line to Plot in R
- ggplot2 Plot with Transparent Background in R
- Draw Vertical Line to X-Axis of Class Date in ggplot2 Plot
- Set Area Margins of ggplot2 Plot
- Plots in R
- R Programming Examples
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.
Statistics Globe Newsletter