[R] Odp: problems with plots in loop (corrected Email)
Petr PIKAL
petr.pikal at precheza.cz
Wed Jun 15 09:59:51 CEST 2011
Hi
r-help-bounces at r-project.org napsal dne 14.06.2011 18:28:42:
> Andreas Betz <abetz at portola.com>
> Odeslal: r-help-bounces at r-project.org
>
> 14.06.2011 18:28
>
> Komu
>
> <r-help at r-project.org>
>
> Kopie
>
> Předmět
>
> [R] problems with plots in loop (corrected Email)
>
> Dear helpers,
>
>
>
> In an attempt to use a loop to generate graphs in a for loop in run into
> a problem. The plan is to fill each page with eight graphs (mfrow =
> c(4,2)) in to two columns. Only the buttom graphs ( meaning every fourth
> graph) have tick labels on the x axis to preserve space. I used an if
> .... Else statement to achieve that.
>
> The problem is that the first eight graphs are skipped when I run the
> loop, the other graphs are fine. However, all graphs can be generated
> individually. This indicates that the data sets are fine.
>
>
>
>
>
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist[[i]])
>
> Generating the first derivative and multiply it by 100 to adjust for the
> scale.
>
>
>
> Here is the code.
>
>
>
> pdf('F:/diffnormal_16001a.pdf')
> par(mfcol = c(4,2))
> for(i in 1: 92){
> fit <- NULL
> der <- NULL
> Zeit <- NULL
> Zeit <- seq(0,300)
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> fit <- smooth.spline(Zeit, guess)
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
> if((i/4)%%1 ==0){par(mar =c(4,4,0, 0) + 0.1)}
> else{par(mar =c(0,4,0, 0) + 0.1)}
Maybe the else just moved due to mailer but it shall be on the same line
as if statement to be executed. But in that case you would obtain error
message.
However when I get rid of all I do not have from your code
pdf("test.pdf")
par(mfcol = c(4,2))
for(i in 1: 8){
fit <- NULL
der <- NULL
Zeit <- NULL
Zeit <- seq(0,300)
if((i/4)%%1 ==0){par(mar =c(4,4,0, 0) + 0.1)} else{par(mar =c(0,4,0,
0) + 0.1)}
leg = paste("Data_", i,sep = "")
plot(Zeit, Zeit, pch = 19, cex=3, ylab = "Signal", axes = F)
if((i/4)%%1 ==0){axis(1, at = seq(0, 360, length = 6), label = c(),
font = 2)}
mtext(side = 3, leg, line = -2)}
dev.off()
It seems to me that plotting works as expected.
Regards
Petr
> leg = paste("Data_", i,sep = "")
> plot(resultslist_1600[[i]], type = "all", pch = ".", ylab = "Signal",
> log = "", axes = F)
> lines(Zeit, der)
> if((i/4)%%1 ==0){axis(1, at = seq(0, 360, length = 6), label = c(),
> font = 2)}
> axis(2, at =
> pretty(na.omit(eval(parse(text=paste("bleeder1600[,",i,"]",sep =""))))),
> label = c())
> mtext(side = 3, leg, line = -2)}
>
>
>
> I understand, that I am supposed to submit working code. However, I deal
> with a fairly comprehensive data set and I have to generate a large list
> using another R package. Thus I explain what it does:
>
>
>
> Generate time points(Zeit <- seq(0,300)
>
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist_1600[[i]])
>
> Test if prediction can be done
>
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> (it turned out it can be done for all data set, as I am able to generate
> the graphs for each data set from the command line individually.
>
> Generating the first derivative and multiply it by 100 to adjust for the
> scale.
>
> fit <- smooth.spline(Zeit, guess)
>
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
>
>
>
> The problem appears to be hidden in the mfrow statement.
>
> I spent quite a bit of time on this problem, thus any help or new ideas
> would be very much appreciated.
>
>
>
> Thank you
>
>
>
> Andreas Betz
>
> Scientist
>
> andreasbetz@ Dear helpers,
>
>
>
> In an attempt to use a loop to generate graphs in a for loop in run into
> a problem. The plan is to fill each page with eight graphs (mfrow =
> c(4,2)) in to two columns. Only the buttom graphs ( meaning every fourth
> graph) have tick labels on the x axis to preserve space. I used an if
> .... Else statement to achieve that.
>
> The problem is that the first eight graphs are skipped when I run the
> loop, the other graphs are fine. However, all graphs can be generated
> individually. This indicates that the data sets are fine.
>
>
>
>
>
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist[[i]])
>
> Generating the first derivative and multiply it by 100 to adjust for the
> scale.
>
>
>
> Here is the code.
>
>
>
> pdf('F:/diffnormal_16001a.pdf')
> par(mfcol = c(4,2))
> for(i in 1: 92){
> fit <- NULL
> der <- NULL
> Zeit <- NULL
> Zeit <- seq(0,300)
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> fit <- smooth.spline(Zeit, guess)
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
> if((i/4)%%1 ==0){par(mar =c(4,4,0, 0) + 0.1)}
> else{par(mar =c(0,4,0, 0) + 0.1)}
> leg = paste("Data_", i,sep = "")
> plot(resultslist_1600[[i]], type = "all", pch = ".", ylab = "Signal",
> log = "", axes = F)
> lines(Zeit, der)
> if((i/4)%%1 ==0){axis(1, at = seq(0, 360, length = 6), label = c(),
> font = 2)}
> axis(2, at =
> pretty(na.omit(eval(parse(text=paste("bleeder1600[,",i,"]",sep =""))))),
> label = c())
> mtext(side = 3, leg, line = -2)}
>
>
>
> I understand, that I am supposed to submit working code. However, I deal
> with a fairly comprehensive data set and I have to generate a large list
> using another R package. Thus I explain what it does:
>
>
>
> Generate time points(Zeit <- seq(0,300)
>
> Pulling the results from a nonlinear regression to more than 90 data
> sets from a list (resultslist_1600[[i]])
>
> Test if prediction can be done
>
> try(guess <- predict(resultslist_1600[[i]]) )
> if(class(guess) == "try-error") {next}
> (it turned out it can be done for all data set, as I am able to generate
> the graphs for each data set from the command line individually.
>
> Generating the first derivative and multiply it by 100 to adjust for the
> scale.
>
> fit <- smooth.spline(Zeit, guess)
>
> der <- 100*(predict(fit, Zeit, deriv = 1))$y
>
>
>
> The problem appears to be hidden in the mfrow statement.
>
> I spent quite a bit of time on this problem, thus any help or new ideas
> would be very much appreciated.
>
>
>
> Thank you
>
>
>
> Andreas Betz
>
> Scientist
>
> andreasbetz at earthlink.net <mailto:andreasbeyz at earthlink.net>
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list