I want to export a ggplot as JPEG with 300dpi for print but whatever I do I get a file with 72dpi (on macOS 10.15.6, RStudio 1.3.1073, R version 4.0.2).
I tried both methods as explained here: Saving a high resolution image in R but neither are working.
Here's some sample data:
x <- c("a", "b", "c")
y <- c(2, 3, 4)
df <- data.frame(x, y)
# ggplot
gg <- ggplot(df, aes(x=x, y=y)) + geom_point()
# method 1
print(gg)
ggsave("method1.jpg", dpi = 300)
# method 2
jpeg("method2.jpg", units = "in", width = 5, height = 5, res = 300)
print(gg)
dev.off()
Thanks in advance!
EDIT: I tried the same using a base R plot (as in boxplot(df$y)
) but that didn't work either.
EDIT2: I tried the same setting the size (as in ggsave('method1.jpg', width = 5, height = 5, dpi = 300)
) which also didn't work