I'm creating a scatterplot using ggplot in R (R version 3.2.1). I want to save the graph as a tiff image in 300 DPI in order to publish it in a journal. However, my code using ggsave or tiff() with dev.off doesn't seem to work and only saves it in 96 DPI. Any help would be greatly appreciated!! Below is a sample of my code using both methods:
library(ggplot2)
x <- 1:100
y <- 1:100
ddata <- data.frame(x,y)
library(ggplot2)
#using ggsave
ggplot(aes(x, y), data = ddata) +
geom_point() +
geom_smooth(method=lm, fill = NA, fullrange=TRUE, color = "black")
ggsave("test.tiff", units="in", width=5, height=4, dpi=300, compression = 'lzw')
#using tiff() and dev.off
tiff('test.tiff', units="in", width=5, height=4, res=300, compression = 'lzw')
ggplot(aes(x, y), data = ddata) +
geom_point() +
geom_smooth(method=lm, fill = NA, fullrange=TRUE, color = "black")
dev.off()
The output is a 96 DPI with a width of 1500 pixels and a height of 1200 pixels.