0

I need to save all my ggplots (as svg files) with the requirement below: "All images must have a minimum resolution of 300 dpi,width 107 mm".

Thus I specified these arguments with ggsave():

library(tidyverse)
plot <- iris %>% 
  ggplot() +
  geom_density(aes(x = Sepal.Length, fill = Species)) +
  scale_x_continuous(breaks = seq(0,10, 0.1))
plot
ggsave(plot, width = 10.7, dpi = 300, unit = "cm", file = "plot.svg")

However, this results in a squished graphic with overlapping text. How can I scale the plot to the requested requirements?

I have tried scaling = 0.5 but how am I meant to guess the correct value for scaling and the height as well?

Thanks

Axeman
  • 32,068
  • 8
  • 81
  • 94
CyG
  • 382
  • 1
  • 12
  • See e.g. https://www.tidyverse.org/blog/2020/08/taking-control-of-plot-scaling/ – Axeman Oct 16 '22 at 19:18
  • 1
    You explicitely require 100 breaks in your `scale_x_continuous(...)` definition. At a plot width of 10.7 cm that leaves about 1 cm space to hold three two-digit labels (not counting the decimal separator). Thus labels *must* overlap at any still legible font-size. You could either settle for fewer breaks, rotate the labels to vertical or leave the choice to ggplot. –  Oct 16 '22 at 19:30
  • Yes, the 100 breaks are necessary as they highlight some issues I have with several plots that I cannot post here (not reproducible) – CyG Oct 17 '22 at 10:14

0 Answers0