当我保存使用的 ggplot 时geom_raster
,瓷砖“被涂抹”了。如果我使用的话结果是一样的ggsave()
or pdf()
。我没有这个问题geom_tile
or 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()