Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

graphics - Create Editable plots from R

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Other editable formats:

Take a look at help(devices) for other formats which are available: these include svg, pictex and xfig, 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:

 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.

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:

#!/usr/bin/Rscript
x = 1:10
pdf("myplot.pdf", height=0, width=0, paper="a4")
plot(x)
dev.off();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...