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.
- 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.
Subscribe to the Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Welcome to the Statistics Globe newsletter. From now on, I’ll send you regular emails about statistics, data science, AI, and programming with R and Python.
I’m Joachim Schork. On this website, I provide statistics tutorials as well as code in Python and R programming.
Statistics Globe Newsletter
Get regular updates on the latest tutorials, offers & news at Statistics Globe. I hate spam & you may opt out anytime: Privacy Policy.
Thank you!
Please check your email inbox and click the confirmation link to complete your subscription. If you don’t see the email within a few minutes, please also check your spam/junk folder.






