Consider this simple example
library(dplyr)
library(ggplot)
library(patchwork)
mytib <- tibble(group = as.factor(c(1,1,1,1,2,2,2,2,3,3,3,3)),
y = c(1,2,3,42,50,400,3,3,2,3,3,4),
x = c('a','b','c','d','a','b','c','d','a','b','c','d'))
p1 <- mytib %>% ggplot(aes(x = x, y = y, fill = group)) +
geom_col() + ggtitle('this is a messy chart')+
coord_flip()+
xlab('Hello') +
ylab('This is a nice comment')
Now I use patchwork
to combine the charts so that I obtain 3 rows of 3 charts each on a regular a4
pdf page
(p1 + p1 + p1)/
(p1 + p1 + p1)/
(p1 + p1 + p1)
ggsave(file="a4_output.pdf", width = 210, height = 297, units = "mm")
The output is a nice a4 pdf
but the problem is that the charts on the pdf
are very stretched. Is there a way to preserve their original ratio (on the pdf) so that they look less stretched, even three on a single row? I dont mind if they look smaller.
Any ideas? Thanks!