[R] how to use a list to create a plot

John Kane jrkrideau at yahoo.ca
Tue Jul 21 15:49:19 CEST 2009


It looks like a data.frame to me.  Try str(psd) or class(psd) to check.  Typeof returns "list" for a data.frame since "data.frame" apparently is a subset of "list".  The 'months' that you are seeing are simply the rownames which by chance are the same as the months.

I's suggest adding the months to the data.frame and then plotting

psd <- xx
psd[,4] <- 1:12
names(psd)[4] <- "months"

plot(sd~months, data=psd)



--- On Tue, 7/21/09, Graves, Gregory <ggraves at sfwmd.gov> wrote:

> From: Graves, Gregory <ggraves at sfwmd.gov>
> Subject: [R] how to use a list to create a plot
> To: r-help at r-project.org
> Received: Tuesday, July 21, 2009, 8:20 AM
> I issued the following command to
> obtain the std dev for each month.
> 
>  
> 
> psd<-numSummary(Sal, groups=month, statistics=c("sd"))
> 
>  
> 
> which resulted in
> 
>  
> 
> > psd
> 
>                
> sd               
>            n   
>           NA
> 
> 1             
> 6.930340             
> 9367 2319
> 
> 2             
> 7.847003             
> 10827 1008
> 
> 3             
> 5.962308             
> 12988  404
> 
> 4             
> 3.632105             
> 12576  384
> 
> 5             
> 3.328189             
> 13030  362
> 
> 6             
> 10.101336           
> 12955    5
> 
> 7             
> 11.759585           
> 13071  321
> 
> 8             
> 10.277566            12286
> 1105
> 
> 9             
> 8.561922             
> 12286  674
> 
> 10       
>    9.252890         
>     13343   27
> 
> 11       
>    9.568852         
>     12591  369
> 
> 12       
>    9.622851         
>     12020  946
> 
>  
> 
> > typeof(psd)
> 
> [1] "list"
> 
>  
> 
> I want plot sd versus column 1 (month of year) of the list
> psd.
> 
>  
> 
> The only way I can figure out how to do this is to manually
> copy the
> table into Excel, reformat, and then export that back out
> as a new csv.
> There has to be a better way?
> 
>  
> 
>  
> 
> Gregory A. Graves
> 
> Lead Scientist
> 
> REstoration COoordination and VERification (RECOVER) 
> 
> Watershed Division
> 
> South Florida Water Management District
> 
> Phones:  DESK: 561 / 682 - 2429 
> 
>          
>    CELL:  561 / 719 - 8157
> 
>              
> 
>  
> 
>  
> 
> 
>     [[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.
> 


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/




More information about the R-help mailing list