[R-sig-eco] Line Plot from a subset of a data frame

Tom_Philippi at nps.gov Tom_Philippi at nps.gov
Mon Feb 13 23:43:41 CET 2012


Ben--

One of many ways would be to use xyplot() in the lattice package.  xyplot()
allows you to specify different colors or symbols within a plot via
groups=, and specify multiple figures in different panels via |Species in
the formula.  You don't need to subset anything, and can produce
identically-scaled figures for each species all in one function call.

I think that you want something like:

xyplot(Mantel.r~Distance|SPECIES,groups=Site.Type,data=FullDataSet)

You can add a simple key (legend) via:
MyPlot <- xyplot(Mantel.r~Distance|SPECIES,groups=Site.Type,data=acfl,
          auto.key=list(space="bottom",columns=3))
print(MyPlot)

You may want to specify layout= to control how many plots are on a page, or
something like layout=c(1,1) to put each figure on a separate page.

Perhaps the trickiest part is to specify your own choice of colors for the
lines.  For that you may need to modify superpose.line:
supline <- trellis.par.get("superpose.line")
supline$col <- c("red","blue","green")
trellis.par.set("superpose.line",supline)
print(MyPlot)

I recommend help(xyplot) as a place to get started.

Tom 2

-------------------------------------------
Tom Philippi, Ph.D.
Quantitative Ecologist
Inventory and Monitoring Program
National Park Service
c/o Cabrillo National Monument
1800 Cabrillo Memorial Dr
San Diego, CA 92106
(619) 523-4576
Tom_philippi at NPS.gov
http://science.nature.nps.gov/im/monitor
-------------------------------------------



                                                                           
             bpdilla                                                       
             <padilla.31 at bucke                                             
             yemail.osu.edu>                                            To 
             Sent by:                  r-sig-ecology at r-project.org         
             r-sig-ecology-bou                                          cc 
             nces at r-project.or                                             
             g                                                     Subject 
                                       Re: [R-sig-eco] Line Plot from a    
                                       subset of a data frame              
             02/13/2012 02:01                                              
             PM PST                                                        
                                                                           
                                                                           
                                                                           
                                                                           




Hi.

I have a data frame with two sets of variables, one continuous Distance
variable, the other a correlation response variable.  I also have a column
that contains an ordinal variable of three types - here is an example.

   DISTANCE Mantel.r SPECIES Site.Type Migratory.Status
1   0.00000  0.14121    ACFL       ALL          MIGRANT
2  12.22267  0.07678    ACFL       ALL          MIGRANT
3  18.70522 -0.17162    ACFL       ALL          MIGRANT
4  24.18015 -0.12109    ACFL       ALL          MIGRANT
5  34.60731  0.11119    ACFL       ALL          MIGRANT
6   0.00000 -0.72777    ACFL     RURAL          MIGRANT
7   5.12862 -0.33734    ACFL     RURAL          MIGRANT
8   5.65393  0.07193    ACFL     RURAL          MIGRANT
9  32.73115  0.01347    ACFL     RURAL          MIGRANT
10 36.31511  0.08692    ACFL     RURAL          MIGRANT
11  0.00000  0.47739    ACFL     URBAN          MIGRANT
12  2.31889  0.25079    ACFL     URBAN          MIGRANT
13  3.75088  0.04259    ACFL     URBAN          MIGRANT
14 11.94983  0.06237    ACFL     URBAN          MIGRANT
15 14.24218 -0.14643    ACFL     URBAN          MIGRANT

I want to make a line plot for each species (ACFL is one of 16 species I
have) that contains three lines, one for ALL, RURAL, and URBAN.  What is
the
best way that I can do this without creating a subset for each group?  For
example, would I have to create
####
ALL=subset(acfl,acfl$Site.Type=='ALL')
##and then##
plot(ALL$DISTANCE,ALL$Mantel.r,type='o')


I would love some help!  Thanks.

Ben

--
View this message in context:
http://r-sig-ecology.471788.n2.nabble.com/Line-Plot-from-a-subset-of-a-data-frame-tp7282081p7282093.html

Sent from the r-sig-ecology mailing list archive at Nabble.com.

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



More information about the R-sig-ecology mailing list