This might not be particularly elegant, but if you put your initial
plot() outside of the loop and then use the loop to place your points,
you might get what you want.  If others have better solutions, I'd be
interested as well.  Note that if you take this approach, you might want
to specify xaxt="n" and yaxt="n" and draw your own axes.

 

plot(NA,NA,xlim=c(-30,100), ylim=c(-30,90), ...);

for(i in 1:query) {

  points(..);

 

  #count increments

}

axis(...)

 

 

________________________________

From: Mohan Singh [mailto:Mohan.Singh@ucd.ie] 
Sent: Wednesday, March 25, 2009 3:00 PM
To: Nutter, Benjamin
Cc: r-help@r-project.org
Subject: Re: [R] Plot inside For loop



basically the for loop goes something like this



setCounters(135);



for(i in 1:query) {

 plot(c2data[start1:count,],c3data[start1:count,],xlim=c(-30,100),
ylim=c(-30,90), sub=i);

 points(..);



  #count increments

}



so if i use windows() or x11(), i get different plot windows



if I use par(), i get one plot, but it redraws on top of previous plots,
so if my query goes from 1 to 5, it plots 5 plots on top of each other,
which in some ways, is ok, but doesn't go well for putting it in a
publication.



i want to draw a single plot with additional data from each for loop..
as the loop proceeds, it adds another set of data onto the previous plot
, i suppose, it doesn't redraw the axis and labels and just plot the
data



Mohan





On 25 Mar 2009, at 18:43, Nutter, Benjamin wrote:





I understood this to mean you want to open a new plotting window on each
iteration of the loop.  If this is correct, I usually go about it by
using x11()

If you're looking to add additional lines or points, then you may want
to look at the aptly named functions lines() and points().

If neither of these are your goal, then I'm afraid I'll need more
clarification on what you're trying to do.

Benjamin

-----Original Message-----
From: r-help-bounces@r-project.org [mailto:r-help-bounces@r-project.org]
On Behalf Of Mohan Singh
Sent: Wednesday, March 25, 2009 1:54 PM
To: r-help@r-project.org
Subject: [R] Plot inside For loop

Hi

  I am plotting a set of data inside a for loop.

  Is it possible to use plot in for loop without redrawing the whole  
plot? Am using par(new=TRUE) but that draws on top of the previous plot.

  Couldn't find any threads about the topic.

Thanks
Mohan
--

______________________________________________
R-help@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.


===================================

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.



--

CASL, MLG

UCD, Dublin 

+353-85-7279622












===================================

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.

	[[alternative HTML version deleted]]


