2013-03-26 5 views
5

Rにはカラーバーとラスターマップを作成しようとしていますが、pdfにエクスポートしたときに出力された数字は見苦しい行を与えます。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

お試しください 'rasterImage' – baptiste

+0

あなたのpdfは私のマシンで素晴らしいです。 –

答えて

5

これは、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上で二つの異なるPDFビューア(示すとOkular)で、あなたのPDFファイルを閲覧し、これらのアーティファクトは、ファイルに影響を与えたの度合いは、二つの間で異なっていましたOkularは赤緑色の人工物を少なく、青黄色の人工物は少ない。このように、Rを使ってPDFを見るのではなく、何かではないと思われるので、あなたの姿は出版品質でなければなりません。

+0

うわー、ありがとう!エヴァンスは、他のほとんどすべてのためにまだ良いままです。 –

関連する問題