0

I've created a complex multi-facet figure using ggplot. When I save it using the basic ggsave command:

ggsave("myplot.pdf", plot = my.plot)

The margins of the figure facets and of the labels get changed.

What it looks like in the Rstudio plot preview:

Rstudio preview:
Rstudio preview

The PDF created by ggsave with altered margin thickness:

ggsave export:
ggsave export

Using the following commands:

pdf("myplot.pdf")
print(my.plot)
dev.off() 

Or using the Rstudio pdf export function or cowplot

save_plot() is even worse, as now the label font size also gets changed:

pdf() export:
pdf() export

Is there a more reliable tool to create PDFs? I'd like it to look the same as in Rstudio. Apologies for not posting the entire code as the source dataframe is very complicated, I'll try to create a reproducible example in the meantime.

benson23
  • 16,369
  • 9
  • 19
  • 38
Nereus
  • 47
  • 5
  • 1
    welcome to SO. the Rstudio preview is kind of never what you get when saving the plot. Font size is a constant, so the relative size changes depending on your so called device size. In ggsave, you set it with "width" and "height" arguments – tjebo Dec 31 '20 at 13:09
  • 3
    (This said, you should not fine tune your plot based on the RStudio preview pane) – tjebo Dec 31 '20 at 13:13

0 Answers0