gpt4 book ai didi

r - R中图形的pdf中有难看的白线

转载 作者:行者123 更新时间:2023-12-04 15:00:37 25 4
gpt4 key购买 nike

我正在尝试在 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

我需要把它提高到出版质量。关于如何修复的任何想法?

最佳答案

这始终是用于呈现 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 查看器(Evince 和 Okular)中查看了您的 PDF,并且这些人工制品影响文件的程度在这两个查看器中是不同的,Okular 在红绿色一个上提供较少的人工制品,在蓝色上没有提供- 黄色的。因此,这似乎是查看 PDF 的问题,而不是 R 的问题。因此,您的数字应该是出版物质量。

关于r - R中图形的pdf中有难看的白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15628463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com