如何在R中保存网格图? [英] How to save a grid plot in R?

查看:135
本文介绍了如何在R中保存网格图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网格图对象g.

I have a grid plot object g.

class(g)
"gtable" "grob"   "gDesc" 

我可以使用grid.draw(g)绘制图.但是,我不知道将图保存到pdf文件的方法.

I can use grid.draw(g) to draw the plot. However, I cannot figure out a way to save the plot to a pdf file.

我尝试过:

ggsave(g, file="plot.png")

但是ggsave显然不适用于这样的对象.

But apparently ggsave doesn't work on such an object.

以下是来自?grid.draw帮助页面的示例:

Here is an example from the ?grid.draw help page:

grid.newpage()
## Create a graphical object, but don't draw it
l <- linesGrob()
## Draw it
grid.draw(l)

绘图效果很好,但是保存/打印会导致问题.

Drawing works well, but saving/printing causes the problem.

对此有任何解决方法?谢谢!

Any workaround on this? Thanks!

推荐答案

这是MrFlick回答的,但对于PDF(您在问题中要问的内容).

This is what MrFlick answered, but for PDFs (what you asked for in your question).

## Initiate writing to PDF file
pdf("path/to/file/PDFofG.pdf", height = 11, width = 8.5, paper = "letter")

## Create a graphical object g here
g # print it

## Stop writing to the PDF file
dev.off()

这篇关于如何在R中保存网格图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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