- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to reduce the space between two plots that are joined with grid.arrange in R?
When we join or combine plots using grid.arrange the scales of the first plot comes in between as X-axis even if the independent variable in both of the plots is same.
Therefore, we might want to remove the space between the plots while joining to get only one X-axis. This can be done by using theme function.
Consider the below data frame −
set.seed(123) x<-rnorm(10,1) y<-rnorm(10,2) df<-data.frame(x,y) df
x y 1 0.4395244 3.22408180 2 0.7698225 2.35981383 3 2.5587083 2.40077145 4 1.0705084 2.11068272 5 1.1292877 1.44415887 6 2.7150650 3.78691314 7 1.4609162 2.49785048 8 -0.2650612 0.03338284 9 0.3131471 2.70135590 10 0.5543380 1.52720859
Loading ggplot2 and gridExtra package −
Creating scatterplot and line chart between x and y with plot.margin to reduce the space between the plot when joined with grid.arrange −
Joining the two plots −
- Related Articles
- How to display a list of plots with the help of grid.arrange in R?
- How to change the size of plots arranged using grid.arrange in R?
- How to separate strings in R that are joined with special characters?
- How to reduce the space between Y-axis value and ticks using ggplot2 in R?
- How to replace space between two words with underscore in an R data frame column?
- How to put space between words that start with uppercase letter in string vector in R?
- How to create two 3d plots at a time in R?
- How to arrange a list of scatterplots in R using grid.arrange?
- How to change the space between bars in a barplot in R?
- How to increase the space between horizontal legends using ggplot2 in R?
- How to show multiple ggplot2 plots with Plotly using R?
- How to create sample space of throwing two dices in R?
- How to create two plots using ggplot2 arranged in a vertical manner in R?
- How to create the plots arranged in a list that were generated using ggplot2 in R?
- Drawing lines between two plots in Matplotlib