Johnston, Danielle
2009-Nov-10 00:01 UTC
[R] creating multiple plots using a splitting factor
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]]
Gabor Grothendieck
2009-Nov-10 00:21 UTC
[R] creating multiple plots using a splitting factor
hist(distance_cm, breaks = 10) is the **output** of a function and is not itself a function. On the other hand, function(distance_cm) hist(distance_cm, breaks = 10) is a function. On Mon, Nov 9, 2009 at 7:01 PM, Johnston, Danielle <Danielle.Bilyeu at state.co.us> 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. >
Petr PIKAL
2009-Nov-10 07:30 UTC
[R] Odp: creating multiple plots using a splitting factor
Hi r-help-bounces at r-project.org napsal dne 10.11.2009 01:01:06:> 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 dataYou could also consider lattice and/or ggplot2 packages for that. Regards Petr> 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Johnston, Danielle
2009-Nov-10 20:37 UTC
[R] creating multiple plots using a splitting factor
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) ofspecific> variables for each site. I have tried to do this by splitting thedata> 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 bysite:> > 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >