保存为PDF时,geom_raster出现"模糊"

sha*_*ker 10 pdf r ggplot2

当我保存使用的ggplot时,geom_raster瓷砖会" 抹掉".如果我使用ggsave()或者是相同的结果pdf().我没有这个问题geom_tileimage.我对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()
Run Code Online (Sandbox Code Playgroud)

eip*_*i10 13

这可能是由于您的PDF查看器对栅格进行了插值.我在我的Mac上重新创建了"smeared2.pdf"(见下文),它在Adobe Reader中看起来很好(右)并在预览中模糊(左).根据您的PDF查看器,您可以通过更改设置来消除模糊效果.例如,在"预览"中,在"首选项"下的"PDF"选项卡中,您可以取消选中"平滑文本和艺术线条",PDF将正确显示.

在此输入图像描述

  • 哇,我不知道观众可能会引起这个问题。浪费时间... (2认同)