我正在使用R(R版本3.2.1)中的ggplot创建散点图.我想将图表保存为300 DPI中的tiff图像,以便将其发布到日记中.但是,我的代码使用ggsave或tiff()与dev.off似乎不起作用,只保存在96 DPI中.任何帮助将不胜感激!!下面是使用这两种方法的代码示例:
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()
Run Code Online (Sandbox Code Playgroud)
输出为96 DPI,宽度为1500像素,高度为1200像素.