Generate and save series of plots with common structure?

46 views
Skip to first unread message

Art Burke

unread,
Feb 22, 2013, 6:08:53 PM2/22/13
to ggp...@googlegroups.com

Consider a data frame with the following structure:

 

df1 <- data.frame(y = runif(10),x1 = runif(10), x2 = runif(10), x3 = runif(10))

 

Is there a way to generate, for example, all the scatterplots of the x’s with y and write them out?

 

Thanks!

Art

 

Brian Diggs

unread,
Feb 22, 2013, 6:32:10 PM2/22/13
to Art Burke, ggplot2
Is this what you are looking for?

library("reshape2")
df2 <- melt(df1, id.var="y")
library("ggplot2")
ggplot(df2, aes(value, y)) + geom_point() + facet_wrap(~variable)

--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Art Burke

unread,
Feb 22, 2013, 7:52:43 PM2/22/13
to ggplot2
Thanks, Brian, but that's not quite what I want. A colleague demonstrated a Stata script that created a series of scatterplots from the data in memory and wrote each of them into a separate file. I'm wondering how to do that with ggplot2.

Art
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Matthew Krachey

unread,
Feb 22, 2013, 8:20:53 PM2/22/13
to Art Burke, ggplot2
Something like:

df1 <- data.frame(y = runif(10),x1 = runif(10), x2 = runif(10), x3 = runif(10))
cols = colnames(df1)[-1]

for(i in cols){
ggplot(df1, aes(x=df1[[i]], y)) +geom_point()
ggsave(paste("y_v",i,".pdf",sep=""))
} 

?

Stuart Luppescu

unread,
Feb 23, 2013, 11:17:37 AM2/23/13
to Art Burke, ggp...@googlegroups.com
Try ggpairs() in the GGally package.
--
Stuart Luppescu <s...@ccsr.uchicago.edu>

Art Burke

unread,
Feb 27, 2013, 5:05:34 PM2/27/13
to ggp...@googlegroups.com

Can someone point me to a ggplot2 example of overlaying images such as in the right side of this one?

 

https://twitter.com/CollegeBoard/status/306827227264319488/photo/1

 

Thanks!

Art

_______________________________________

Arthur Burke

Education Northwest | Senior Methodology Advisor

101 SW Main St, Suite 500; Portland OR 97204

503.275.9592

Art....@educationnorthwest.org

http://educationnorthwest.org

 

 

 

 

Ista Zahn

unread,
Feb 27, 2013, 5:51:29 PM2/27/13
to Art Burke, ggp...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages