PDF和位图输出中R中的颜色渐变 [英] Color gradients in R in PDF and bitmap output

查看:207
本文介绍了PDF和位图输出中R中的颜色渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力获得R中视觉上可接受的颜色渐变(请参见

I am struggling to get a visually acceptable color gradient in R (see here for a detailed description of my particular case). The problem, in short, is that while output in the R window looks OK, PDFs show thin, white lines between segments used to generate the gradient.

n <- 100
cc <- colorRampPalette(c("red", "blue"))(n)
plot.new()
par(mar=rep(0,4))
sapply(1:n, function(i) rect((i-1)/n, 0, i/n, 1, col=cc[i], border=NA))
dev.copy2pdf(file="test.pdf")

这是结果:

您可以看到细的白线.它们的位置取决于缩放比例,因此我认为它们是PDF显示方式的产物.在另一个缩放中也是如此:

You can see the thin, white lines. Their positioning depends on the zoom, so I assume that they are an artifact of how the PDF is displayed. Here the same in another zoom:

不幸的是,这些行在打印输出上也可见.我想问题可能出在将矢量图形渲染到位图以进行显示或打印时,PDF中的坐标如何取整.

Unfortunately, these lines are also visible on a printout. I guess the problem may be with how the coordinates in the PDF get rounded when the vector graphics is rendered to bitmap for display or printing.

可能的解决方案是使用彼此重叠的段.这仅适用于纯色;不幸的是,我也想在渐变中使用透明的颜色.

A possible solution would be to use segments which overlap with each other. This is acceptable only for solid colors; unfortunately, I would like to use transparent colors in the gradients as well.

我该怎么做才能使我的PDF输出更好?

What can I do to make my output in PDF better?

推荐答案

这似乎纯粹是由于渲染器引起的问题.例如:

This seems to be an issue purely due to the renderer. E.g.:

我不认为您可以对PDF进行任何更改以从根本上解决问题.就我而言,Adobe Acrobat在任何缩放级别上都看起来不错,除了在非常高的缩放下(我必须去3200%缩放才能看到白线).

I don't believe there's anything you can change about the PDF to fundamentally fix the issue. In my case, Adobe Acrobat looked good at any zoom level except at very high zoom (I had to go to 3200% zoom to see white lines).

此外,Chrome和Microsoft Edge似乎运行良好.

Also, Chrome and Microsoft Edge seemed to work well.

这篇关于PDF和位图输出中R中的颜色渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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