'loop FOR' for make plots

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

'loop FOR' for make plots

Cleber N.Borges

Hello

How to create plots dynamically with results of several analysis ?

I got many outputs from lm fuction like:

mp1.lm mp2.lm mp3.lm mp4.lm mp5.lm ...

I'd like to make experimental versus predicted response plots of all
analysis
in a 'for loop':

for( i in 1:10){
x11()

plot(  mp*i*$experimental_response, fitted( mp*i* ) ); abline(0,1)

}

I tried: paste( 'mp', i, sep=''), but it don't work.


How to make this reference?


Regards

Cleber

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: 'loop FOR' for make plots

Don MacQueen
There are undoubtedly many ways to do this.

See the get() function.

for( i in 1:10) {
   nm <- paste( 'mp',i,'.lm',sep='')
   tmp <- get( nm )
   plot(  tmp$experimental_response, fitted(tmp) )
   abline(0,1)
   title(nm)
   readline('CR to continue ')
}

And you may need to specify pos or envir in get()


Another way would be to put your outputs from lm in a list, which you
could do at the time you create them, instead of afterwords, as here:

lmout <- list(mp1=mp1.lm, mp2=mp2.lm, mp3=mp3.lm)
lapply(
     lmout,
     function(ff)   {  plot(ff$experimental_response,fitted(ff)) ;
abline(0,1)  }
)

I haven't tested these precisely; there may be typographical errors.

-Don

At 7:14 PM -0100 3/30/06, klebyn wrote:

>Hello
>
>How to create plots dynamically with results of several analysis ?
>
>I got many outputs from lm fuction like:
>
>mp1.lm mp2.lm mp3.lm mp4.lm mp5.lm ...
>
>I'd like to make experimental versus predicted response plots of all
>analysis
>in a 'for loop':
>
>for( i in 1:10){
>x11()
>
>plot(  mp*i*$experimental_response, fitted( mp*i* ) ); abline(0,1)
>
>}
>
>I tried: paste( 'mp', i, sep=''), but it don't work.
>
>
>How to make this reference?
>
>
>Regards
>
>Cleber
>
>______________________________________________
>[hidden email] mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: 'loop FOR' for make plots

jholtman
In reply to this post by Cleber N.Borges
Instead of creating separate objects for each one, why not just a list to
hold the data.  Instead of having mp1.lm ... mp10.lm, you would have mp.lm[[1]]
... mp.lm[[10]] and therefore your loop could look like:

for( i in 1:10){
x11()

plot(  mp[[i]]$experimental_response, fitted( mp[[i]]) ); abline(0,1)

}


If you really want to use separate variable, look at 'get'.


On 3/30/06, klebyn <[hidden email]> wrote:

>
>
> Hello
>
> How to create plots dynamically with results of several analysis ?
>
> I got many outputs from lm fuction like:
>
> mp1.lm mp2.lm mp3.lm mp4.lm mp5.lm ...
>
> I'd like to make experimental versus predicted response plots of all
> analysis
> in a 'for loop':
>
> for( i in 1:10){
> x11()
>
> plot(  mp*i*$experimental_response, fitted( mp*i* ) ); abline(0,1)
>
> }
>
> I tried: paste( 'mp', i, sep=''), but it don't work.
>
>
> How to make this reference?
>
>
> Regards
>
> Cleber
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>



--
Jim Holtman
Cincinnati, OH
+1 513 646 9390 (Cell)
+1 513 247 0281 (Home)

What the problem you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html