I need to make about 30 figures and I am trying to create a program in R that will make my life a lot easier. First I will tell you how my data is setup. I have 30 sites and then data for each year at the site. I have 10 years of data for each site. Below is a small chunk of my data to show the format. 2000 2001 2002 2003 2004 Site A 50 75 25 55 60 Site B 58 22 68 77 30 I am trying to write a program in R that will create figures showing the annual data for each individual site. As opposed to making 30 individual graphs in Excel. Any help would be greatly appreciated. -- View this message in context: http://r.789695.n4.nabble.com/help-with-making-figures-tp4645074.html Sent from the R help mailing list archive at Nabble.com.
First convert your data from short fat to long thin format: Column headings for the transformed data frame are: Year Site Result This can be done in a variety of ways, but check out the reshape2 package or the reshape function ins the stats package. Once you have the data in this form, , say in the data frame, mydat, you can plot the series by sites in a trellised layout. Either the lattice or ggplot2 package can do this easily. e.g. in lattice it is: xyplot(Result ~Year|Site, data = mydat, type = "b") You can adjust the layout etc. to your taste. There's lots more you can do, depending on what is important to you, but that should get you started. Cheers, Bert On Thu, Oct 4, 2012 at 1:01 PM, megalops <megalops31 at hotmail.com> wrote:> I need to make about 30 figures and I am trying to create a program in R that > will make my life a lot easier. First I will tell you how my data is setup. > I have 30 sites and then data for each year at the site. I have 10 years of > data for each site. Below is a small chunk of my data to show the format. > 2000 2001 2002 2003 2004 > Site A 50 75 25 55 60 > Site B 58 22 68 77 30 > > I am trying to write a program in R that will create figures showing the > annual data for each individual site. As opposed to making 30 individual > graphs in Excel. Any help would be greatly appreciated. > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/help-with-making-figures-tp4645074.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
It's helpful to provide reproducible code in your posting to R help. The dput() function can be used to share some of your data. For example, you might have used dput(mydata[1:10, 1:10]) # here's some data I made up as an example ... df <- structure(list(`2000` = c(44L, 31L, 55L, 83L, 39L, 12L, 21L, 20L, 52L, 63L, 92L, 90L, 22L, 71L, 23L, 46L, 84L, 9L, 98L, 47L ), `2001` = c(88L, 11L, 61L, 86L, 6L, 78L, 97L, 70L, 10L, 72L, 14L, 37L, 94L, 60L, 8L, 19L, 73L, 57L, 2L, 30L), `2002` = c(29L, 87L, 56L, 17L, 4L, 95L, 3L, 77L, 53L, 24L, 79L, 48L, 59L, 42L, 54L, 28L, 25L, 18L, 43L, 15L), `2003` = c(16L, 40L, 58L, 65L, 13L, 38L, 76L, 41L, 1L, 66L, 32L, 45L, 5L, 51L, 33L, 82L, 68L, 74L, 91L, 69L), `2004` = c(67L, 7L, 75L, 80L, 99L, 89L, 81L, 93L, 62L, 85L, 64L, 35L, 100L, 34L, 50L, 49L, 27L, 96L, 36L, 26L)), .Names = c("2000", "2001", "2002", "2003", "2004"), row.names = c("Site A", "Site B", "Site C", "Site D", "Site E", "Site F", "Site G", "Site H", "Site I", "Site J", "Site K", "Site L", "Site M", "Site N", "Site O", "Site P", "Site Q", "Site R", "Site S", "Site T"), class = "data.frame") # transpose the data (switch columns and rows) df.turned <- as.data.frame(t(df)) # site names sites <- names(df.turned) # years year <- as.numeric(dimnames(df.turned)[[1]]) # a separate plot for each site for(i in seq(sites)) { plot(year, df.turned[, i], type="b", xlab="Year", ylab="My data", main=sites[i]) } Jean megalops <megalops31@hotmail.com> wrote on 10/04/2012 03:01:17 PM:> > I need to make about 30 figures and I am trying to create a program in Rthat> will make my life a lot easier. First I will tell you how my data issetup.> I have 30 sites and then data for each year at the site. I have 10years of> data for each site. Below is a small chunk of my data to show the > format. > 2000 2001 2002 2003 2004 > Site A 50 75 25 55 60 > Site B 58 22 68 77 30 > > I am trying to write a program in R that will create figures showing the > annual data for each individual site. As opposed to making 30individual> graphs in Excel. Any help would be greatly appreciated.[[alternative HTML version deleted]]
Maybe Matching Threads
- How to extract from a column in a table?
- Plotting the probability curve from a logit model with 10 predictors
- discriminant function analysis
- output and save multiple dataset from a function: sorry I could not figure out this....
- How to evaluate sequence of strings like this