我正在尝试使用 ggplot2 的 geom_raster() 生成热图。这是代码:
foo <- matrix(1:999,ncol=3)
ggplot(melt(foo), aes(X2,X1, fill=value)) + geom_raster()
结果是:
但是在将输出转换为 PDF 文件(使用pdf()
函数)时,结果是如此不同:
有许多列,列之间的颜色逐渐变化。如何在将输出转换为 PDF 文件时获得与第一个相同的热图?
Some pdf viewers don't manage properly the output of grid.raster
, even with interpolate=FALSE
they insist on showing some spurious gradient.
Your pdf most probably is good (as per the pdf format specifications), it's the pdf viewer that is deficient (overzealous to smooth).
Try to see if you have some preferences in the viewer to turn off interpolation and/or a different pdf viewer, e.g. in Mac's Preview application, one can switch "smooth text and line art" off and see the expected output. There's a similar option in the cross-platform Adobe Reader.