[R] Plotting from a list

Gabor Grothendieck ggrothendieck at gmail.com
Fri Nov 14 00:11:33 CET 2008


Convert it to long form and plot like this (or look at ggplot2 for
another approach):

DF <- structure(list(A = c(8.423645, 30.881773, 29.783251, 17.827586,
27.507389, 17.46798, 8.167488, 32.502463, 44.610837), B = c(0.208,
27.344, 15.824, 31.776, 30.52, 27.232, 0, 19.736, 11.208), C = c(1.6296296,
13.2592593, 24.3333333, 14.7777778, 12.2222222, 34.2592593, 1.4074074,
34.6666667, 1.7777778), D = c(0, 26.2962963, 26.3333333, 23.8888889,
30.8518519, 42.4074074, 0, 39.8888889, 15.6296296), E = c(0,
22.3090909, 19.5090909, 25.2, 25.8363636, 45, 0, 28.5272727,
17.8545455), F = c(0, 22.4545455, 34.4545455, 21.7272727, 13.7272727,
34.0909091, 0, 43.6363636, 7.5454545)), .Names = c("A", "B",
"C", "D", "E", "F"), class = "data.frame", row.names = c("1965",
"1966", "1967", "1968", "1969", "1970", "1971", "1972", "2000"
))

library(lattice)
long <- as.data.frame.table(as.matrix(DF), responseName = "Pop")
barchart(Pop ~ Var2 | Var1, long)


On Thu, Nov 13, 2008 at 4:30 PM,  <Steve_Friedman at nps.gov> wrote:
> Hi again,
>
> Yes you are right   I should have included an example of the file
>
> It looks like this after reading in the data and using tapply I arrive at
> the following
>
>> Alt5rimc_mean
>             A      B          C          D          E          F
> 1965  8.423645  0.208  1.6296296  0.0000000  0.0000000  0.0000000
> 1966 30.881773 27.344 13.2592593 26.2962963 22.3090909 22.4545455
> 1967 29.783251 15.824 24.3333333 26.3333333 19.5090909 34.4545455
> 1968 17.827586 31.776 14.7777778 23.8888889 25.2000000 21.7272727
> 1969 27.507389 30.520 12.2222222 30.8518519 25.8363636 13.7272727
> 1970 17.467980 27.232 34.2592593 42.4074074 45.0000000 34.0909091
> 1971  8.167488  0.000  1.4074074  0.0000000  0.0000000  0.0000000
> 1972 32.502463 19.736 34.6666667 39.8888889 28.5272727 43.6363636
> ...
> 2000 44.610837 11.208  1.7777778 15.6296296 17.8545455  7.5454545
>
> I do not have example code, to share, but I was initially thinking that it
> should be approached with as follows:
>
> for (i in 1 to 6)             #  index for columns
>  for (j in 1 to 36)        # index for rows
>
> barplot(data[i][j])
>
>
> But that is very crude and of course it does not work.  Hence the request
> for assistance.
>
> Thanks
>
> Steve Friedman Ph. D.
> Spatial Statistical Analyst
> Everglades and Dry Tortugas National Park
> 950 N Krome Ave (3rd Floor)
> Homestead, Florida 33034
>
> Steve_Friedman at nps.gov
> Office (305) 224 - 4282
> Fax     (305) 224 - 4147
>
>
>
>             "jim holtman"
>             <jholtman at gmail.c
>             om>                                                        To
>                                       Steve_Friedman at nps.gov
>             11/13/2008 04:04                                           cc
>             PM EST                    "R help" <R-help at stat.math.ethz.ch>
>                                                                   Subject
>                                       Re: [R] Plotting from a list
>
>
>
>
>
>
>
>
>
>
> Yes you can automate it.  The exact way would depend on how your data
> is structured and what you want the graphs to look like.  It is hard
> to say without an example of the data and at least the command that
> your are using to create a single plot.
>
> On Thu, Nov 13, 2008 at 2:16 PM,  <Steve_Friedman at nps.gov> wrote:
>>
>> Hello,
>>
>> I am working with version 2.7.2 on a PC and have 2.8.0 available, but
> have
>> not upgraded completely yet.
>>
>> I have 6 species for which I've run 6 unique environmental management
>> scenarios against for comparison purposes.  Each scenario is run for 36
>> years (1965 - 2000).  Some of the species have subpopulations and other
> do
>> not.   For those with subpopulations (A, B, C, D, E, and F) I have
>> calculated basic summary statistics.
>>
>> I would like to develop a series of barplots  for each scenario year
>> consisting of six bars representing the subpopulations.  Rather than
>> writing 36 lines of code, I'd like to automate this with a loop process,
>>
>> Any suggestions ?
>>
>> Thanks
>>
>> Steve Friedman Ph. D.
>> Spatial Statistical Analyst
>> Everglades and Dry Tortugas National Park
>> 950 N Krome Ave (3rd Floor)
>> Homestead, Florida 33034
>>
>> Steve_Friedman at nps.gov
>> Office (305) 224 - 4282
>> Fax     (305) 224 - 4147
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem that you are trying to solve?
>
> ______________________________________________
> 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