An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130307/225e3bbb/attachment.pl>
multiple plots and looping assistance requested (revised codes)
2 messages · Irucka Embry, arun
HI Irucka,
The situation is slightly different here.? I was under the assumption that the list elements sometimes had one two columns or three columns.? Here, all the columns are present, but some with entire rows of missing values.? Also, there was a mistake in the code when I updated the code.
If the real data is similar to the one posted here, I guess it should work.
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<-lapply(temp3,function(x) lapply(names(x)[-1], function(i) {x1<-cbind(x[,1],x[,i]);colnames(x1)<- c("Month",i);x1} ))
pdf("Irucka3.pdf")
par(mfrow=c(1,2))
lapply(names(temp3New),function(i) lapply(temp3New[[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()
#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("Irucka2.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()
Please let me know if there are problems.
A.K.
From: Irucka Embry <iruckaE at mail2world.com>
To: smartpink111 at yahoo.com
Cc: r-help at r-project.org
Sent: Friday, March 8, 2013 1:15 AM
Subject: Re: [R] multiple plots and looping assistance requested (revised codes)
To: smartpink111 at yahoo.com
Cc: r-help at r-project.org
Sent: Friday, March 8, 2013 1:15 AM
Subject: Re: [R] multiple plots and looping assistance requested (revised codes)
Hi Arun, thanks for the responses. 1) I added more data to the data set located at http://stackoverflow.com/questions/11548368/making-multiple-plots-in-r-from-one-textfile to more resemble the actual data set that I have. The example data set is called tempdata. I have used the most recent code suggestions for plotting on the example data set and I am receiving the same error message as with the full data set. I figured that the plot function is stopping at Atlantacitydata and it is not going further because Atlantacitydata is a blank plot. How do I get plot to keep plotting after encountering a blank plot in a multi plot series? I have looked online and I have not found an answer yet. -------------- next part -------------- A non-text attachment was scrubbed... Name: Irucka2.pdf Type: application/pdf Size: 4880 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130308/9d271204/attachment.pdf> -------------- next part -------------- A non-text attachment was scrubbed... Name: Irucka3.pdf Type: application/pdf Size: 8503 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130308/9d271204/attachment-0001.pdf>