当我保存使用geom_raster
的ggplot时,瓷砖会出现"涂抹"。如果我使用ggsave()
或pdf()
,结果会相同。我对geom_tile
或image
没有这个问题。我对RStudio,X11或PNG图形设备没有这个问题。
造成这种情况的原因是什么?我该如何解决?
示例:
library(ggplot2)
## doesn't work: tiles are smeared together
ggsave("smeared1.pdf",
ggplot(cbind(expand.grid(x = 1:3, y = 1:3), fill = rnorm(9))) +
geom_raster(aes(x = x, y = y, fill = fill)))
pdf("smeared2.pdf")
ggplot(cbind(expand.grid(x = 1:3, y = 1:3), fill = rnorm(9))) +
geom_raster(aes(x = x, y = y, fill = fill))
dev.off()
## works fine
ggsave("not-smeared0.png",
ggplot(cbind(expand.grid(x = 1:3, y = 1:3), fill = rnorm(9))) +
geom_raster(aes(x = x, y = y, fill = fill)))
ggsave("not-smeared1.pdf",
ggplot(cbind(expand.grid(x = 1:3, y = 1:3), fill = rnorm(9))) +
geom_tile(aes(x = x, y = y, fill = fill)))
pdf("not-smeared2.pdf")
ggplot(cbind(expand.grid(x = 1:3, y = 1:3), fill = rnorm(9))) +
geom_tile(aes(x = x, y = y, fill = fill)))
dev.off()
pdf("not-smeared3.pdf")
image(matrix(rnorm(9), 3))
dev.off()
答案 0 :(得分:11)
这可能是由于您的PDF查看器正在执行interpolation of the raster。我重新创建了你的" smeared2.pdf"在我的Mac上(见下文),它在Adobe Reader(右)中看起来很好,在预览(左)中模糊。根据您的PDF查看器,您可以通过更改设置来消除模糊效果。例如,在“预览”中,在“首选项”下的“PDF”选项卡中,您可以取消选中"平滑文本和线条艺术"并且PDF将正确显示。