I am having trouble with saving publication-ready plots in ggplot2, or perhaps just don't understand how ggplot2/ggsave works. The following code saves a plot on my computer that is roughly 20"x20" with 72 dpi. I need to plot to be roughly 5"x5" with > 300 dpi.
you have made a 1500 by 1500 image. if there should be a dpi of 300 this would be 5inch dimensions. I don't know what application you are using to show you image dimensions...
what happens when you change 72 to 300 ?
The image is opened in preview (mac's default viewer). I'm using the 'show inspector' window in the tools drop-down to view the DPI. If I change the resolution to 300 in preview, it changes to 300, but that's beside the point.
(I can manually scale the image in preview after saving in R to pass the journal's standards, but I'd rather just understand how ggsave works so I can automate it)
I think this is a mac inspector issue though, isnt it ?
if you change the resolution to 300 in preview, does mac inspector reconsider its size assumptions? I'm not on a mac to verify anything, but on a windows pc, theres nothing problematic with the image. its 1500 pixes x 1500 pixels . it can therefore be rendered out to a medium at whatever dpi/physical size combinations are mathematically possible.
It will be for any application that opens it, to consider how it wants to render those 1500 pixels, whether to use one dpi or another. I think the png standard does support dpi metadata, but its not a requirement, its generally not a required thing...
or. in laymans terms, providing an image that is without a doubt 1500pixles by 1500 pixels, is providing an image that can be rendered at 300dpi over 5x5inches. (it could also be rendered out to other physical dimensions, but thats up to the publisher to decide)
Oh interesting. So the mac preview is probably opening it at the screen resolution (72 dpi) and so it suggests the size (in inches) is quite large. But in reality, it is 300 dpi at 5"x5". This sounds like a problem with the journal then. ( I realize I left out this context....journal is asking for higher dpi plots; the ones I sent in were >4000x4000 pixels...)
This is perhaps orthogonal to the original question, but does the journal accept .svg images? In that case they can render it at any dpi/size they need on their end.
That's interesting and potentially helpful. Image formats are pretty foreign to me. SVG files aren't listed in the journal's author resources, but it looks like the manuscript software allows svg files to be uploaded. Perhaps I'll offer that as a potential solution to the editor. Thank you!
If you don't have a good reason to have it be .png, I find that printing to PDFs and its true type font scaling makes one able to resize later at will, with no loss in resolution. I actually print to pdf at the dimensions desired, but then can share/scale later if needed. And you can convert later from pdf -> other formats at will.