Support for dpi parameter in `ggsave()`
Currently, there is no support for dpi parameter in ggsave() . This comes handy when saving to png and it is present in the R version of ggplot.
Hi! Could you please describe your use case, how would you use the DPI parameter? What exactly should this parameter affect (set meta info in a PNG file, image resolution, plot size)? We have the scale parameter that works in a similar way. Can this parameter work in your cases?
Thank you!
Hi,
DPI is for resolution. You're right scale works in a very similar way. Using pixels makes more sense of course. But in some cases, mostly for printing, people have to use inches or centimeters for dimensions which are then converted to pixels according to given DPI parameter. This eliminates the need for manual calculation to satisfy those requirements. Here are the ggplot2 and matplotlib implementation for reference.
So, using DPI also somewhat necessitates the use of dimensions in terms of inches, centimeters etc., In terms of conversion, 1 pixel = 1/96th of an inch or 1 point = 1/72nd of an inch (source). Addition of cm, inch could also help people export vector images with the desired sizes too.
In a sense, when the dimensions are provided, they should override scale and be converted into pixels for both vector images and png images. For png images, DPI parameter is also required for resolution in such cases. Default value for dpi in matplotlib and ggplot2 are 72 and 300, respectively.
Hope this helps!
This helps a lot. Thank you!
Hi guys,
I happen to need to ggsave() a plot with particular width and height in cm, as a .pdf. After struggling a little I found that ggsave() does save plots in 96 dpi, is that right ? And I also found that the scale option works for pdf too ! (the doc still indicates that it only works when exporting in png.)
I agree with @Zaf4, dpi option would be nice !
It makes me think that the possibility to directly use cm or pixels in ggsave() would be awesome too !
Hi @Zaf4 , @egayer Currently, one point is not well understood: the effects observed in matplotlib when the plot size is constant and DPI is varied. Specifically, the sizes of plot elements (font size, line width, etc.) are scaled up with increasing DPI, as shown in @IKupriyanov-HORIS's post above. Is this the desired behavior?
Specifically, the sizes of plot elements (font size, line width, etc.) are scaled up with increasing DPI
That's one of things I don't like about matplotlib. I think DPI should not change the size of plot elements at all and higher figsize should not result in proportionally smaller plot elements. DPI should only effect the resolution of raster images like scale.
Basically, size parameters such as cm, inch should effect pdf, svg dimensions and dpi should dictate the raster image resolution.
once again, great job ;) thanks you guys, it works perfectly !