R:保存为 PDF 时可以修复图例吗?
运行此代码时
plot(c(0,1), c(0, 1), type = "n")
legend("topleft", legend = c("Model", "Data"),
lwd = c(3, NA),
pch = c(NA, 16),
bty = "n", inset = 0.02,
cex = 2)
当我按预期 ,我看到以下内容:
但是,当我将其包装在 pdf("legendTest.pdf")
.. . dev.off()
,保存的PDF有一条穿过该点的线。
我可以更正这个问题,还是需要以其他格式保存?我使用的是 Mac,使用预览和 Chrome 查看 PDF 时出现问题。我下载了 Adobe Reader 看看它做了什么,然后图例文本和 pch 点消失了,只留下模型线。
When I run this code
plot(c(0,1), c(0, 1), type = "n")
legend("topleft", legend = c("Model", "Data"),
lwd = c(3, NA),
pch = c(NA, 16),
bty = "n", inset = 0.02,
cex = 2)
as expected, I see this:
However, when I wrap it in pdf("legendTest.pdf")
... dev.off()
, the saved PDF has a line through the point.
Can I correct this, or do I need to just save in another format? I'm on a Mac, and the problem is present viewing the PDF using Preview and Chrome. I downloaded Adobe Reader to see what it did, and then the legend text and pch point disappeared, leaving only the model line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过显式设置线类型(参数
lty
)来解决此问题,如下所示:编辑
lwd
参数的文档,位于?par
解释说:Mac 的默认 R 图形设备一定是其中之一。 (FWIW,使用您的代码,我自己的 Windows 图形设备确实显示一条穿过数据点的线,就像在 pdf 中一样。)
无论如何,看起来使用
通常更安全lty
比lwd
来控制这个特定的细节。You can fix this by explicitly setting the line type (argument
lty
), like this:EDIT
The documentation for the
lwd
argument, in?par
explains that:Mac's default R graphical device must be one of those. (FWIW, with your code, my own Windows graphics device does show a line through the data point, just as in the pdf.)
In any case, it looks like it's generally safer to use
lty
thanlwd
to control this particular detail.