Reputation: 2234
I have 4 graphs that I want to display using grid.arrange()
. When I display them individually, they look like this:
But when I use grid.arrange()
, they become distorted
with them individually looking like
Specific Issues:
I want to reproduce each plot exactly like the first ideal case in a grid with grid.arrange()
. One possible way might be to convert each plot to an image and then use grid.arrange()
but I don't know how to do this.
Below is an example reproducible code that shows the problem I am having.
p1 <- ggplot(subset(mtcars, cyl = 4), aes(wt, mpg, colour = cyl)) + geom_point() + labs(title = "TITLE-TITLE-TITLE-TITLE-TITLE-TITLE", subtitle = "-subtitle-subtitle-subtitle-subtitle-subtitle-subtitle-subtitle-") +theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5))
p2 <- ggplot(subset(mtcars, cyl = 4), aes(wt, mpg, colour = cyl)) + geom_point() + labs(title = "TITLE-TITLE-TITLE-TITLE-TITLE-TITLE", subtitle = "-subtitle-subtitle-subtitle-subtitle-subtitle-subtitle-subtitle-") +theme(plot.title = element_text(hjust = 0.5),plot.subtitle = element_text(hjust = 0.5))
grid.arrange(p1, p2, ncol = 2)
Upvotes: 3
Views: 2955
Reputation: 48211
When you display those graphs individually they simply have more space. So, those are natural distortions and there are perhaps only three ways to solve that.
When exporting the combined graph, make it big enough. If the individual one looks good in 6x5 inches, then surely the combined one will look good in 12x10 inches.
Give correspondingly less space for the problematic parts: x-axis labels and the subtitle. For instance, use something like element_text(size = 6)
for plot.subtitle
and axis.title.x
, add \n
to the subtitles and even x-axis labels, try something like element_text(angle = 30)
for the latter as well.
Get rid of something unnecessary. As @Richard Telford suggests in the comments, using facet_wrap
should work better. That would be due to, e.g., not repeating the y-axis labels and, hence, giving more horizontal space.
Upvotes: 2