提高 R 和 ggplot2 中 EMF 输出的质量

发布于 2024-11-19 10:09:41 字数 707 浏览 1 评论 0原文

我正在使用 ggplot2 和 win.graph 命令生成并保存 EMF 文件。输出图形质量低下,线条看起来参差不齐。我确实需要 EMF 格式(导出为 pdf 可以解决问题,但我需要 EMF 文件)。我怎样才能使它高质量? (emf 输出位于此处,以防您想查看)

require(ggplot2)
my.dates = as.Date(c("2011-07-22","2011-07-23",
                     "2011-07-24","2011-07-28","2011-07-29"))
my.vals  = c(5,6,8,7,3)
my.data <- data.frame(date =my.dates, vals = my.vals)
plot(my.dates, my.vals)
p <- ggplot(data = my.data, aes(date,vals))+ geom_line(size = 1.5)
p <- p + scale_x_date(format="%m/%d", ' ')
win.graph(width=860/72, height=450/72,pointsize = 12)

print(p)
savePlot("c:/test.emf",type="emf")
dev.off()

I am generating and saving an EMF file with ggplot2 and with the win.graph command. the output graph is low quality and lines looked jagged. I really need to have it in EMF format (exporting to pdf solves the problem but I need the EMF file). How can I make it high quality? (the emf output is here in case you like to see it)

require(ggplot2)
my.dates = as.Date(c("2011-07-22","2011-07-23",
                     "2011-07-24","2011-07-28","2011-07-29"))
my.vals  = c(5,6,8,7,3)
my.data <- data.frame(date =my.dates, vals = my.vals)
plot(my.dates, my.vals)
p <- ggplot(data = my.data, aes(date,vals))+ geom_line(size = 1.5)
p <- p + scale_x_date(format="%m/%d", ' ')
win.graph(width=860/72, height=450/72,pointsize = 12)

print(p)
savePlot("c:/test.emf",type="emf")
dev.off()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找我们的幸福 2024-11-26 10:09:41

EMF 是基于矢量的。我将 EMF 文件粘贴到 powerpoint 幻灯片中,我注意到它们呈现为低分辨率。如果右键单击 EMF 文件并选择编辑照片,它将正确渲染。这解决了我的问题。

更新:
我继续编写了一个小 VBA 脚本来取消 EMF 文件的分组。它将其分解为一个可以轻松缩放的图形对象。现在看起来非常好。

EMF is vector based. I was pasting the EMF files into powerpoint slides and I noticed that they are rendered as low res. If you right click on the EMF file and select edit photo it will render it properly. That solved my problem.

Update:
I went ahead and wrote a little VBA script that ungroups the EMF file. It breaks it into a graph object that can be easily scaled. It looks very nice now.

落墨 2024-11-26 10:09:41

您可以将 ggplot 保存为 SVG,然后使用 Inkscape 对其进行后处理。
它易于使用、免费且效果极佳。

You can save your ggplot as SVG and then post-process it with Inkscape.
It's easy to use, free and gives great results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文