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

gen*_*ser 6 graphics r

我正在尝试在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()
Run Code Online (Sandbox Code Playgroud)

这是我作为PDF格式出来的:

链接

我需要达到出版质量.有关如何修复的任何想法?

Rei*_*son 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.

     ....
Run Code Online (Sandbox Code Playgroud)

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