n.vialma at libero.it
2011-Jun-24 19:29 UTC
[R] try to generate graph for each element of my list
Dear all, I have the following problem. I have a List of time series dataframe.I'm trying to produce specific graph for each element of my list. The code is: This is my list: Lista_import<-lapply(Lista_import, function(x){ x2<-subset(x, select=c("ANNO","DICHIARANTE","PARTNER", "quota")) x2<-cast(x2, ANNO+DICHIARANTE~PARTNER) x2<- as.xts(as.matrix(as.timeSeries(x2))) return(x2)}) each list have the following shape: $AUS $DEU and data inside...I'm not showing you the content cause I think is not relevant For the GRaph the code is c<-lapply(Lista_import,function(x){ for(i in names(Lista_import)){ legenda <- read.csv ("/home/fturrini/Tessile/01_Dati_complementari/Legenda_paese.csv",header=TRUE) leg <- data.frame(ISO3=colnames(x),inutile=1) legenda <- merge(legenda,leg, by="ISO3", all.y=TRUE) png(paste("/home/Tessile/Output/Gra/MaxM/QuoteEXperPaese_",i,".png"), width=1661,height=828) graph <-{par(bg="grey97", font=3,font.axis=3,bty="l",las=1, mar=c(8,6,4,2), xpd=FALSE) yrange<-c(min(x,na.rm=TRUE), 1.05*max(x,na.rm=TRUE)) colori <- c("Blue","Aquamarine1", "Firebrick3", "Chocolate4", "BlueViolet", "Yellow3") chart.TimeSeries(x, type="l",lwd=5, ylab="", xlab="", main="", date.format="% Y", ylim=yrange, col=colori, cex.axis=1.6, major.ticks="years", minor.ticks=FALSE, grid.color="gray50", grid.lty="dotted") legend("topleft",as.character(legenda$PAESE),bty="n",cex=1.7,lwd=5, ncol=2, col=colori, horiz=F) mtext("Fonte: Unctad, Pctas", side=1,line=5,adj=1,cex=1.8,col="grey20") mtext(p, side=1,line=5,adj=0,cex=1.5,col="grey10")}} dev.off() rm(grafico) }) The results is that I get the same graph for each element of my list..... Someone knows how to get one graph for each element of my list pasting the names' list element in the .png file?? Thanks for your attention!
On 24.06.2011 21:29, n.vialma at libero.it wrote:> Dear all, > I have the following problem. I have a List of time series dataframe.I'm > trying to produce specific graph for each element of my list. The code is: > This is my list: > Lista_import<-lapply(Lista_import, function(x){ > x2<-subset(x, select=c("ANNO","DICHIARANTE","PARTNER", "quota")) > x2<-cast(x2, ANNO+DICHIARANTE~PARTNER) > x2<- as.xts(as.matrix(as.timeSeries(x2))) > return(x2)}) > > > each list have the following shape: > $AUS > $DEU > and data inside...I'm not showing you the content cause I think is not > relevant > > > For the GRaph the code is > > c<-lapply(Lista_import,function(x){ > for(i in names(Lista_import)){ > > legenda<- read.csv > ("/home/fturrini/Tessile/01_Dati_complementari/Legenda_paese.csv",header=TRUE)The lihne above is independent from i in the loop, hence move it outside and rename the stuff below.> leg<- data.frame(ISO3=colnames(x),inutile=1) > legenda<- merge(legenda,leg, by="ISO3", all.y=TRUE) > > png(paste("/home/Tessile/Output/Gra/MaxM/QuoteEXperPaese_",i,".png"), > width=1661,height=828)- >ou should really prettify your code in order to make it readable. Use tabs and spaces where appropriate! - You probably want paste(....., sep="") above> > graph<-{par(bg="grey97", font=3,font.axis=3,bty="l",las=1, mar=c(8,6,4,2), > xpd=FALSE) > yrange<-c(min(x,na.rm=TRUE), 1.05*max(x,na.rm=TRUE)) > colori<- c("Blue","Aquamarine1", "Firebrick3", "Chocolate4", "BlueViolet", > "Yellow3") > > chart.TimeSeries(x, type="l",lwd=5, ylab="", xlab="", main="", date.format="% > Y", ylim=yrange, col=colori, > cex.axis=1.6, major.ticks="years", minor.ticks=FALSE, grid.color="gray50", > grid.lty="dotted") > legend("topleft",as.character(legenda$PAESE),bty="n",cex=1.7,lwd=5, ncol=2, > col=colori, horiz=F)You want to write FALSE rather than F above. I have not found the actual error, since your example is nopt reproducible and we do not know how your data look like. Uwe Ligges> mtext("Fonte: Unctad, Pctas", side=1,line=5,adj=1,cex=1.8,col="grey20") > mtext(p, side=1,line=5,adj=0,cex=1.5,col="grey10")}} > dev.off() > rm(grafico) > }) > > The results is that I get the same graph for each element of my list..... > Someone knows how to get one graph for each element of my list pasting the > names' list element in the .png file?? > Thanks for your attention! > > ______________________________________________ > 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.