'Why am I not getting high-resolution with ggsave()?

I'm trying to get 300 dpi images with ggsave, and am only getting the default 72 dpi.

Here's an example of the code I'm using:

library(tidyverse)
x <- rnorm(100, 5, 1)
x <- tibble(x)
ggplot(x, aes(x = x)) + geom_histogram()
ggsave("hist.png", width = 10, height = 10, units = "in", dpi = 300)

When I run this I get a 72 dpi .png file. I'm using a MAC with Catalina 10.15.7 and updated to the most recent versions of R and ggplot2 today.



Solution 1:[1]

I've got the same issue, followed @Jon Spring url and everything was fixed

After checking each image using inspector, my experience so far was:

# Mixed results
ggsave("img_ggsave.tiff", img,width = 6,height=7, dpi=300, units = "in")

# Does not work for mac
tiff("img_native.tiff", width = 6, height = 7, units = "in", res = 300)
img
dev.off()

# ragg always works for mac
ragg::agg_tiff("img_ragg.tiff", width = 6, height = 7, units = "in", res = 300)
img
dev.off()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Esteban M. Correa