R中的图形的pdf有不美观的白线 [英] pdf of figure in R has unsightly white lines in it

查看:170
本文介绍了R中的图形的pdf有不美观的白线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在R中制作颜色条和栅格贴图,并且输出数字在导出为PDF时给出了难看的线条。

以下是生成颜色条的代码。在R中运行它看起来很好:

  color.bar < - 函数(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)
轴(4,ticks,las = 1)
for(i in 1 :(长度(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 (colorrampPalette(c(goldenrod,pos),min = -75,max = 50,ticks = c(-75,-50,-25,0,25,50))
color.bar (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 (红色,黄色))
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获取的内容:



链接



我需要把它提高到出版质量。关于如何解决这个问题的任何想法?

解决方案

这无疑是用于呈现PDF的软件的问题,不是与R一起使用,并且由于PDF查看器为了显示PDF而执行的反锯齿和其他渲染操作等功能。



这是在?pdf 中讨论过,特别是

 注意:

如果您发现PDF输出存在问题,请记住问题
更可能出现在您的查看器中,而不是R中。如果可能,请尝试另一个
查看器。查看器出现
故障的症状是图像上的明显网格(如果可以,请在查看器中关闭图形
消除锯齿)以及文本中缺少或不正确的
字形(查看器默默地做字体替换)。

不幸的是,大多数Linux和Mac OS X
系统的默认查看器存在这些问题,并且没有明显的方法来关闭
图形反锯齿。

....

我刚刚在两个不同的PDF Linux上的观众(Evince和Okular)以及这两件作品影响文件的程度在两位观众中都不相同,Okular在红绿相间提供的文物较少,而蓝黄相间则没有文物。因此,这似乎是查看PDF而不是R的问题。因此,您的数字应该是出版质量。


I'm trying to make colorbars, as well as raster maps, in R, and the output figures give unsightly lines in them when exported to pdf.

Here is code to generate a colorbar. It looks fine when you run it in 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()

And here is what I get out as a pdf:

link

I need to get this up to publication quality. Any ideas on how to fix?

解决方案

This is invariably an issue with the software used to render the PDF, not with R, and arises because of features such as anti-aliasing and other rendering operations that the PDF Viewer does in order to display the PDF.

This is discussed in ?pdf, notably

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.

     ....

I just viewed your PDF in two different PDF viewers on Linux (Evince and Okular) and the degree to which these artefacts affected the file was different across the two viewers, with Okular giving fewer artefacts on the red-green one and none on the blue-yellow one. As such this seems to be an issue with viewing the PDF and not something with R. Your figure should therefore be publication quality.

这篇关于R中的图形的pdf有不美观的白线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆