Skip to content
Prev 320599 / 398506 Next

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.