我正在 R 中创建一系列绘图(我使用的是 ggplot2,但这不是必需的),我希望能够保存我的输出,以便我可以编辑它以供进一步使用,例如,我可能想移动关于图例,或调整颜色等。我看到 ggplot2 有一个保存命令,但似乎会生成 pdf 或位图,这两者都不是特别可编辑的
其他人如何做到这一点?有什么好主意吗?
这是一些生成示例图的示例代码;
library(ggplot2)
dataframe<-data.frame(fac=factor(c(1:4)),data1=rnorm(400,100,sd=15))
dataframe$data2<-dataframe$data1*c(0.25,0.5,0.75,1)
dataframe
testplot<-qplot(x=fac, y=data2,data=dataframe, colour=fac, geom=c("boxplot", "jitter"))
testplot
谢谢
保罗。
I'm creating a series of plots in R (I'm using ggplot2, but that's not essential) and I want to be able to save my output so I can then edit it for furthur use, For instance, I might want to move legends about, or adjust colours etc. I have seen that ggplot2 has a save command but that seems to produce pdf's or bitmaps, neither of which are particularly editable
How do other people do this ? Any good ideas ?
Here's some sample code to produce a sample plot;
library(ggplot2)
dataframe<-data.frame(fac=factor(c(1:4)),data1=rnorm(400,100,sd=15))
dataframe$data2<-dataframe$data1*c(0.25,0.5,0.75,1)
dataframe
testplot<-qplot(x=fac, y=data2,data=dataframe, colour=fac, geom=c("boxplot", "jitter"))
testplot
Thanks
Paul.
发布评论
评论(4)
其他可编辑格式:
查看
help(devices)
了解其他可用格式:包括svg
、pictex
和xfig
,所有这些都可以或多或少地进行编辑。请注意,可以编辑 PDF,例如使用适用于 Apple OSX 的
Omnigraffle
工具。记录绘图数据的其他方法:
此外,您可以将 R 的命令记录到图形子系统以便稍后重复 - 看看
dev.copy
:使用 Rscript 创建可重复、可编辑的绘图:
I通常采用第三种策略,即将我的 R 会话复制到 Rscript 文件中,我可以重复运行该文件并调整绘图命令,直到它执行我想要的操作:
Other editable formats:
Take a look at
help(devices)
for other formats which are available: these includesvg
,pictex
andxfig
, all of which are editable to greater or lesser extents.Note that PDFs can be edited, for instance using the
Omnigraffle
tool available for Apple's OSX.Other ways to record plot data:
In addition, you can record R's commands to the graphics subsystem for repeating it later - take a look at
dev.copy
:Using Rscript to create a repeatable, editable plot:
I typically take a third strategy, which is to copy my R session into an Rscript file, which I can run repeatedly and tweak the plotting commands until it does what I want:
使用 ggplot 和lattice,您可以使用
save
将绘图对象保存到磁盘,然后加载
并对其进行修改。例如:With ggplot and lattice, you can use
save
to save the plot object to disk and thenload
it later and modify it. For example:感谢您的回答,我已经解决了这个问题,在我的朋友 Google 的帮助下,我找到了 Cairo 包,它允许创建 svg 文件,然后我可以在 Inkscape。
现在,我只需要在编写文件之前尝试各种设置,以使我的绘图尽可能好。
Thanks for the answers, I've played around with this, and after some help from my friend Google I found the Cairo package, which allows creation of svg files, I can then edit these in Inkscape.
Now I just have to play around with the various settings to get my plot as good as it can be before writing the file.
在输出图上单击鼠标右键
复制为图元文件
然后将绘图保存到Word文档中(右键单击编辑图片以将绘图转换为Microsoft Office绘图对象)
right click the mouse on the output plot
Copy as metafile
then save plot into a word document (right click to edit picture to covert to the plot to Microsoft Office drawing Object)