R中的数字的pdf中有难看的白线

时间:2013-03-26 02:42:51

标签: r graphics

我正在尝试在R中制作彩条和光栅贴图,输出数字在导出为pdf时会在其中显示难看的线条。

以下是生成颜色条的代码。在R:

中运行它看起来很好
color.bar <- function(lut, min, max=-min, nticks=11, ticks=seq(min, max, len=nticks), title='') {
    scale = (length(lut)-1)/(max-min)

    plot(c(0,10), c(min,max), type='n', bty='n', xaxt='n', xlab='', yaxt='n', ylab='', main=title)
    axis(4, ticks, las=1)
    for (i in 1:(length(lut)-1)) {
     y = (i-1)/scale + min
     rect(0,y,10,y+1/scale, col=lut[i], border=NA)
    }
}

par(mfrow=c(2,1))
par(mar=c(3,0,3,2.5))
pal = colorRampPalette(c("red","yellow"))
neg = pal(100)
pal = colorRampPalette(c("yellow","darkgreen"))
pos = pal(50)
color.bar(c(neg,pos),min=-75,max=50,ticks=c(-75,-50,-25,0,25,50))
color.bar(colorRampPalette(c("goldenrod","blue"))(25),min=0,max=1)
par(mar=c(5.1,4.1,4.1,2.1))
    dev.copy2pdf(file = "colorbar_wood.pdf", height = 8, width = 1)
pdf("colorbar_wood.pdf",width=1,height=8)
par(mfrow=c(2,1))
par(mar=c(3,0,3,2.5))
pal = colorRampPalette(c("red","yellow"))
neg = pal(100)
pal = colorRampPalette(c("yellow","darkgreen"))
pos = pal(50)
color.bar(c(neg,pos),min=-75,max=50,ticks=c(-75,-50,-25,0,25,50))
color.bar(colorRampPalette(c("goldenrod","blue"))(25),min=0,max=1)
par(mar=c(5.1,4.1,4.1,2.1))
 dev.off()

以下是我作为pdf获得的内容:

link

我需要达到出版质量。关于如何解决的任何想法?

1 个答案:

答案 0 :(得分:6)

这通常是用于渲染PDF的软件的问题,与R一起出现,并且由于PDF查看器为了使用抗锯齿和其他渲染操作等功能而出现问题。显示PDF。

这在?pdf中进行了讨论,特别是

Note:

     If you see problems with PDF output, do remember that the problem
     is much more likely to be in your viewer than in R.  Try another
     viewer if possible.  Symptoms for which the viewer has been at
     fault are apparent grids on image plots (turn off graphics
     anti-aliasing in your viewer if you can) and missing or incorrect
     glyphs in text (viewers silently doing font substitution).

     Unfortunately the default viewers on most Linux and Mac OS X
     systems have these problems, and no obvious way to turn off
     graphics anti-aliasing.

     ....

我刚刚在Linux(Evince和Okular)上的两个不同的PDF查看器中查看过您的PDF文件,这些文物影响文件的程度在两个观看者中有所不同,Okular在红绿色文件上提供的文物较少,没有在蓝黄色的。因此,这似乎是查看PDF而不是R的问题。因此,您的数字应该是出版质量。