Re: [R] multiple plots and looping assistance requested (single plot)
HI Irucka, Please check this: temp- structure(list(`:Bostoncitydata` = structure(list(Month = c(1L, 2L, 3L, NA), Data1 = c(1.5, 12.3, 11.4, NA), Data2 = c(9.1342, 12.31, 3.5, NA)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -4L)), `:Chicagocitydata` = structure(list(Month = c(1L, 2L, 3L, 4L, 5L, NA), Data1 = c(1.52, 12.63, 20.34, 12.83, 3.34, NA ), Data2 = c(19.41342, 13.031, 0.80021, 12.63104, 19.20021, NA )), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -6L)), `:NewYorkcitydata` = structure(list(Month = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, NA), Data1 = c(NA, NA, NA, NA, NA, NA, NA, NA), Data2 = c(3.1342, 1.31, 13.5, 1.31, 2.40021, 0.25, 26.3, NA)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -8L)), `:Philadelphiacitydata` = structure(list(Month = c(1L, 2L, 3L, 4L, 5L, 6L, NA), Data1 = c(1.65, 11.63, 5.0434, 13.73, 3.0234, 34.209, NA), Data2 = c(2.61342, 16.331, 19.040021, 17.831, 10.1010021, 3.80742, NA)), .Names = c(Month, Data1, Data2 ), class = data.frame, row.names = c(NA, -7L)), `:Atlantacitydata` = structure(list( Month = c(1L, 2L, 3L, NA), Data1 = c(NA, NA, NA, NA), Data2 = c(NA, NA, NA, NA)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -4L)), `:Baltimorecitydata` = structure(list(Month = 1:2, Data1 = c(11.325, 32.433), Data2 = c(49.71342, 52.4031)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -2L))), .Names = c(:Bostoncitydata, :Chicagocitydata, :NewYorkcitydata, :Philadelphiacitydata, :Atlantacitydata, :Baltimorecitydata)) temp1-lapply(temp,function(x) {x1-x[,colSums(is.na(x))!=nrow(x)]; if(is.data.frame(x1)) x1[complete.cases(x1),] else x1[complete.cases(x1)] }) # temp1-lapply(temp1,function(x) x[is.data.frame(x)]) #3 columns subset temp3-temp1[lapply(temp1,length)==3] temp3New-temp3[sapply(temp3,is.data.frame)] pdf(Irucka.pdf) lapply(names(temp3New),function(i) {x-temp3New[[i]]; matplot(x[,1],x[,-1],type=n,lty=1,sub=i,main=Seasonal Flux Sum, xlab=Calendar Year Timesteps,ylab=Total Flux (kg/season)); matlines(x[,1],x[,-1],type=l,lty=1:2,lwd=1,col=1:2)}) dev.off() A.K. From: Irucka Embry iruc...@mail2world.com To: smartpink...@yahoo.com Sent: Friday, March 29, 2013 5:41 PM Subject: Re: [R] multiple plots and looping assistance requested (single plot) Hi Arun, I'm sorry about the data not being read correctly. OK, thank you so much! Irucka -Original Message- From: arun [smartpink...@yahoo.com] Sent: 3/29/2013 3:36:21 PM To: iruc...@mail2world.com Subject: Re: [R] multiple plots and looping assistance requested (single plot) HI Irucka, No problem. Thanks for the dput(data), but it seems like the data is not read correctly. It still has comma as separator. str(temp) List of 5 $ 02143500,,:'data.frame':17 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 17 levels ,,,2000.875,,4202.7437226,..: 2 3 4 5 6 7 8 9 10 11 ... $ 02169000,,:'data.frame':17 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 17 levels ,,,2000.875,,227675.73764,..: 2 3 4 5 6 7 8 9 10 11 ... $ 02169500,,:'data.frame':17 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 17 levels ,,,2000.875,,414312.49534,..: 2 3 4 5 6 7 8 9 10 11 ... $ 02169570,,:'data.frame':17 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 17 levels ,,,2000.875,2897.79043403356,5155.6776796,..: 2 3 4 5 6 7 8 9 10 11 ... $ 02172300,,:'data.frame':12 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 12 levels 2001.875,,899.46439731,..: 1 2 3 4 5 6 7 8 9 10 ... I actually found the dataset containing Bostoncitydata, etc.. I will work on that. From: Irucka Embry iruc...@mail2world.com To: smartpink...@yahoo.com Sent: Friday, March 29, 2013 1:35 PM Subject: Re: [R] multiple plots and looping assistance requested (single plot) Hi Arun, that is fine. I want to thank you in advance for your assistance. Irucka -Original Message- From: arun [smartpink...@yahoo.com] Sent: 3/29/2013 10:02:35 AM To: iruc...@mail2world.com Subject: Re: [R] multiple plots and looping assistance requested (single plot) Will look into it later. From: Irucka Embry iruc...@mail2world.com To: smartpink...@yahoo.com Sent: Friday, March 29, 2013 11:02 AM Subject: Re: [R] multiple plots and looping assistance requested (single plot) Hi Arun, how are you? Thank you for the response. Yes, I would like to have the xy scatter plot with connecting lines for both columns to be in the same plot window. I'm sorry that I forgot the data, but it is included below. dput(temp) structure(list(`02143500,,` = structure(list(CYEAR_Decimal.load_00600_W.load_00600_F = structure(c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 1L
Re: [R] multiple plots and looping assistance requested (single plot)
Hi Arun, thank you very much. That code worked perfectly. Below is the full version of the code with the addition of a legend. Irucka rm(list=ls()) source(read.funkyfile.R) temp = read.funkyfile(seasonalFluxComparisonDataSet.csv, station_id, header=TRUE, sep=\t) temp1-lapply(temp,function(x) {x1-x[,colSums(is.na(x))!=nrow(x)]; if(is.data.frame(x1)) x1[complete.cases(x1),] else x1[complete.cases(x1)] }) # temp1-lapply(temp1,function(x) x[is.data.frame(x)]) #3 columns subset temp3-temp1[lapply(temp1,length)==3] temp3New-temp3[sapply(temp3,is.data.frame)] pdf(Calibration_Results/Nitrogen/Graphics/seasonalFluxComparisonDataSet full.pdf) lapply(names(temp3New),function(i) {x-temp3New[[i]]; matplot(x[,1],x[,-1],type=n,lty=1,sub=i,main=Seasonal Flux Sum, xlab=Calendar Year Timesteps,ylab=Total Flux (kg/season)); matlines(x[,1],x[,-1],type=l,lty=1:2,lwd=1,col=1:2); legend(topright, inset=.05, title=Seasonal Flux Methods, lty=c(1,1), col= c(black, red), c(EGRET/WRTDS,Fluxmaster), horiz=TRUE)}) dev.off() #2 columns subset temp2-temp1[lapply(temp1,length)==2] temp2New-lapply(temp2,function(x) lapply(names(x)[-1], function(i) {x1-cbind(x[,1],x[,i]);colnames(x1)- c(Month,i);x1} )) pdf(Calibration_Results/Nitrogen/Graphics/seasonalFluxComparisonDataSet partial.pdf) par(mfrow=c(1,1)) lapply(names(temp2New),function(i) lapply(temp2New[[i]],function(x) {plot(x[,1],x[,2],main=Seasonal Flux Sum,sub=paste(i,colnames(x)[2],sep= ),xlab=Calendar Year Timesteps,ylab=Total Flux (kg/season));lines(x[,1],x[,2])})) dev.off() -Original Message- From: arun [smartpink...@yahoo.com] Sent: 3/29/2013 4:47:57 PM To: iruc...@mail2world.com Cc: r-help@r-project.org Subject: Re: [R] multiple plots and looping assistance requested (single plot) HI Irucka, Please check this: temp- structure(list(`:Bostoncitydata` = structure(list(Month = c(1L, 2L, 3L, NA), Data1 = c(1.5, 12.3, 11.4, NA), Data2 = c(9.1342, 12.31, 3.5, NA)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -4L)), `:Chicagocitydata` = structure(list(Month = c(1L, 2L, 3L, 4L, 5L, NA), Data1 = c(1.52, 12.63, 20.34, 12.83, 3.34, NA ), Data2 = c(19.41342, 13.031, 0.80021, 12.63104, 19.20021, NA )), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -6L)), `:NewYorkcitydata` = structure(list(Month = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, NA), Data1 = c(NA, NA, NA, NA, NA, NA, NA, NA), Data2 = c(3.1342, 1.31, 13.5, 1.31, 2.40021, 0.25, 26.3, NA)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -8L)), `:Philadelphiacitydata` = structure(list(Month = c(1L, 2L, 3L, 4L, 5L, 6L, NA), Data1 = c(1.65, 11.63, 5.0434, 13.73, 3.0234, 34.209, NA), Data2 = c(2.61342, 16.331, 19.040021, 17.831, 10.1010021, 3.80742, NA)), .Names = c(Month, Data1, Data2 ), class = data.frame, row.names = c(NA, -7L)), `:Atlantacitydata` = structure(list( Month = c(1L, 2L, 3L, NA), Data1 = c(NA, NA, NA, NA), Data2 = c(NA, NA, NA, NA)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -4L)), `:Baltimorecitydata` = structure(list(Month = 1:2, Data1 = c(11.325, 32.433), Data2 = c(49.71342, 52.4031)), .Names = c(Month, Data1, Data2), class = data.frame, row.names = c(NA, -2L))), .Names = c(:Bostoncitydata, :Chicagocitydata, :NewYorkcitydata, :Philadelphiacitydata, :Atlantacitydata, :Baltimorecitydata)) temp1-lapply(temp,function(x) {x1-x[,colSums(is.na(x))!=nrow(x)]; if(is.data.frame(x1)) x1[complete.cases(x1),] else x1[complete.cases(x1)] }) # temp1-lapply(temp1,function(x) x[is.data.frame(x)]) #3 columns subset temp3-temp1[lapply(temp1,length)==3] temp3New-temp3[sapply(temp3,is.data.frame)] pdf(Irucka.pdf) lapply(names(temp3New),function(i) {x-temp3New[[i]]; matplot(x[,1],x[,- 1],type=n,lty=1,sub=i,main=Seasonal Flux Sum, xlab=Calendar Year Timesteps,ylab=Total Flux (kg/season)); matlines(x[,1],x[,-1],type=l,lty=1:2,lwd=1,col=1:2)}) dev.off() A.K. From: Irucka Embry iruc...@mail2world.com To: smartpink...@yahoo.com Sent: Friday, March 29, 2013 5:41 PM Subject: Re: [R] multiple plots and looping assistance requested (single plot) Hi Arun, I'm sorry about the data not being read correctly. OK, thank you so much! Irucka -Original Message- From: arun [smartpink...@yahoo.com] Sent: 3/29/2013 3:36:21 PM To: iruc...@mail2world.com Subject: Re: [R] multiple plots and looping assistance requested (single plot) HI Irucka, No problem. Thanks for the dput(data), but it seems like the data is not read correctly. It still has comma as separator. str(temp) List of 5 $ 02143500,,:'data.frame': 17 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 17 levels ,,,2000.875,,4202.7437226,..: 2 3 4 5 6 7 8 9 10 11 ... $ 02169000,,:'data.frame': 17 obs. of 1 variable: ..$ CYEAR_Decimal.load_00600_W.load_00600_F: Factor w/ 17 levels ,,,2000.875,,227675.73764,..: 2 3 4 5 6 7 8 9 10 11 ... $ 02169500,,:'data.frame': 17 obs. of 1 variable