Pau*_*yuk 9 graphics r ggplot2
我在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
Run Code Online (Sandbox Code Playgroud)
谢谢
保罗.
看一下help(devices)
可用的其他格式:这些格式包括svg
,pictex
并且xfig
,所有这些格式都可以在更大或更小的范围内编辑.
请注意,可以编辑PDF,例如使用Omnigraffle
Apple OSX可用的工具.
此外,您可以将R的命令记录到图形子系统以便以后重复 - 请查看dev.copy
:
Most devices (including all screen devices) have a display list
which records all of the graphics operations that occur in the
device. 'dev.copy' copies graphics contents by copying the display
list from one device to another device. Also, automatic redrawing
of graphics contents following the resizing of a device depends on
the contents of the display list.
Run Code Online (Sandbox Code Playgroud)
我通常采取第三种策略,即将我的R会话复制到Rscript文件中,我可以反复运行并调整绘图命令,直到它完成我想要的操作:
#!/usr/bin/Rscript
x = 1:10
pdf("myplot.pdf", height=0, width=0, paper="a4")
plot(x)
dev.off();
Run Code Online (Sandbox Code Playgroud)
感谢您的回答,我已经尝试过这个,在我的朋友 Google 的帮助下,我找到了Cairo包,它允许创建 svg 文件,然后我可以在Inkscape中编辑这些文件。
library(Cairo)
Cairo(600,600,file="testplot.svg",type="svg",bg="transparent",pointsize=8, units="px",dpi=400)
testplot
dev.off()
Cairo(1200,1200,file="testplot12200.png",type="png",bg="transparent",pointsize=12, units="px",dpi=200)
testplot
dev.off()
Run Code Online (Sandbox Code Playgroud)
现在,我只需要在编写文件之前尝试各种设置,以使我的绘图尽可能好。
归档时间: |
|
查看次数: |
4566 次 |
最近记录: |