【发布时间】:2016-12-18 20:25:29
【问题描述】:
我正在使用 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()
输出是 96 DPI,宽度为 1500 像素,高度为 1200 像素。
【问题讨论】:
-
您可能需要设置高度和宽度(和单位)
-
该代码适用于模拟数据!问题应该出在您的情节上,因此需要一个可重现的示例
-
同意。对我来说很好——你的输出的像素尺寸是多少,当你打电话给
ggsave()时 ggplot 说什么?