[R] creating multiple plots using a splitting factor

Johnston, Danielle Danielle.Bilyeu at state.co.us
Tue Nov 10 21:37:00 CET 2009


Thank you for the responses.  The Lattice library is indeed useful for
producing the graphs in which I am interested, and I appreciate the
clarification between a function and the result of a function.  

Ideally, I would like to be able to page through the graphs rather than
(or in addition to) having them displayed on the same page.  Is there a
way to do this?

Danielle B. Johnston, Habitat Researcher
Colorado Division of Wildlife

-----Original Message-----
From: Phil Spector [mailto:spector at stat.berkeley.edu] 
Sent: Tuesday, November 10, 2009 12:46 AM
To: Johnston, Danielle
Subject: Re: [R] creating multiple plots using a splitting factor

Danielle -
    What you meant to say was

lapply(splitlist, function(x)hist(x$distance_cm, breaks=10))

but you might also be interested in trying

library(lattice)
histogram(~distance_cm|site,data=seeddist2)


 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu




On Mon, 9 Nov 2009, Johnston, Danielle wrote:

> Hello,
>
>
>
> I am new to R.  I often collect data at multiple sites and need to
> create separate graphs (such as scatterplots or histograms) of
specific
> variables for each site.  I have tried to do this by splitting the
data
> frame and then using lapply, but it seems that the graphing commands
> cannot be called as functions.  Here is a sample of my data, called
> "seeddist2":
>
>
>
>   site    DaysSinceRelease   distance_cm
>
> 10  GVM       1           17.8
>
> 11  GVM       1           17.8
>
> 12  GVM       1           14.0
>
> 13  GVM       1           14.0
>
> 14  GVM       1           14.9
>
> 15  GVM       1           25.4
>
> 16  WRR       1           25.4
>
> 17  WRR       1           35.0
>
> 18  WRR       1           45.0
>
> 19  WRR       1           55.0
>
> 20  WRR       1           60.0
>
>
>
> Here is what I tried to get separate histograms of distance_cm by
site:
>
> splitlist<- split(seeddist2, site)
>
> lapply(splitlist, hist(distance_cm, breaks=10))
>
>
>
> I then get an error message saying that "match.fun" didn't find the
> function.  Is there another way to produce multiple graphs at once?
>
>
>
> Thank you,
>
>
>
> Danielle B. Johnston, Habitat Researcher
>
> Colorado Division of Wildlife
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list