title: How can I make sure that plots are not cutoff when saving as a jpeg in r?
body: <p>I have created a combined plot with <code>ggarrange</code> which looks good in the plot window, however when I save it as a jpeg at 300dpi A4 size I notice that the legend of plot A and the boxplot titles for plot B get cut off, as if they are not being resized appropriately for the size I specified. I've also noticed that the size of the font in the legend is larger than what it looks on R prior to saving.</p>
  
  <p>Saved image as jpeg
  <img src="https://i.stack.imgur.com/N69FW.jpg" alt="Saved image as jpeg"> </p>
  
  <p>Screenshot from R studio
  <img src="https://i.stack.imgur.com/9PX2h.png" alt="Screenshot from R studio"></p>
  
  <p>These are the codes for my plots:</p>
  
  <p>Plot A</p>
  
  <pre><code>taxaplot2 &lt;- ggplot(group, aes(x = variable, y = value, fill = Species)) +
    geom_bar(position = "fill", stat = "identity") +
    scale_fill_manual(breaks = Species2, values = Cb64k) +
    scale_y_continuous(labels = percent_format()) +
    theme(legend.position = "bottom", text=element_text(size=11),
          axis.text.x = element_text(angle=0, vjust=1)) +
    guides(fill = guide_legend(ncol=5)) +
    facet_grid(cols=vars(group), scales = "free_x", space = "free_x") +
    ggtitle(opt$gtitle) +
    xlab("Patient ID") + ylab("Relative Abundance")
  </code></pre>
  
  <p>Plot B</p>
  
  <pre><code>pl &lt;- ggplot(df.humann2.sub.all4, aes(x=as.factor(PEDIS), y=PathAbundance, fill=as.factor(PEDIS)))
  pl &lt;- pl + geom_boxplot()
  pl &lt;- pl + facet_wrap(~ variable)
  </code></pre>
  
  <p>Combining plots and export</p>
  
  <pre><code>combined_plot &lt;- ggarrange(taxachart2, pl, heights = c(4,1.75), labels=c("A","B"), ncol=1, nrow=2)
  
  jpeg("test2.jpeg", units = "in", width = 8, height = 11, res=300)
  combined_plot
  dev.off()
  </code></pre>
  
  <p>How can I ensure that the saved image will look exactly the same as the screenshot above?</p>