Re: [R] Plot multiple columns

From: baptiste auguie <baptiste.auguie_at_googlemail.com>
Date: Tue, 01 Jun 2010 12:22:28 +0200

Hi,

You could use melt from the reshape package to create a long format data.frame. This is more easy to plot with lattice or ggplot2, and you can then use facetting to arrange several plots on the same page. The dummy example below produces 10 pages of output with 10 graphs per page.

library(ggplot2)

dl <- replicate(10, as.data.frame(matrix(rnorm(1e3), ncol=10)), simplify=FALSE) names(dl) <- paste("column", seq_along(dl), sep="")

# dummy list of data.frames
str(dl)

# a function to plot one data.frame
plotone <- function(d, ...)
  qplot(seq_along(value), value, data=melt(d)) +   facet_wrap(~variable, scales="free")

# call the function for each data.frame
pl <- llply(dl, plotone)

# print to a file
pdf("test.pdf")
l_ply(pl, print)
dev.off()

HTH, baptiste

On 1 June 2010 10:02, Noah Silverman <noah_at_smartmediacorp.com> wrote:
> I'm running a long MCMC chain that is generating samples for 22 variables.
>
> I have each run of the chain as a row in a matrix.
>
> So:  Chain[,1] is the column with all the samples for variable one.
> Chain[,2] is the column with all the samples for variable 2, etc.

>
> I'd like to fit all 22 on a single page to print a nice summary.  It is
> OK if the graphs are small, I just need to show the overall shape and
> convergence.

>
> Using par(mfrow=(11,2)) gives me the error:  "figure margins too large"
> when I try to draw a plot
> I looked at the Lattice package, which seems very promising, but I can't
> figure out how to have it plot each column in a separate box.
>
> I need to do this same "one page" summary about 50 times, so it would be
> a nightmare to make over 1,000 plots by hand.
>
> Ideally, I'd create a loop for each of the 50 runs that would generate a
> single page containing the 22 plots.
>
> In pseudocode:
>
> for( i in 1:50){
>    par(mfrow(11,2))
>    for(j in 1:22){
>        plot(Chain[,j], type="l")
>    }
> }
>
> BUT, this doesn't work.
>
> Does anyone have any ideas about an easy way to do this?
>
> Thanks!
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 01 Jun 2010 - 10:25:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Jun 2010 - 10:40:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive