Re: [R] Changing a plot

2008-09-25 Thread R Help
Thanks, I looked into the grid package.  The grid package does do a
better job of managing the plotting, but it's still re-plotting the
entire canvas whenever a modifcation is made to a plot.

I guess I should have been a little clearer with my question.  Here's
a sample function.

library(tcltk)
x = runif(1)
y = runif(1)
v1 - viewport()
grid.rect(gp = gpar(lty = dashed))
pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
pushViewport(dataViewport(x, y))
grid.rect()
grid.xaxis()
grid.yaxis()
grid.points(x, y)
grid.text(1:10, x = unit(-3, lines), rot = 90)
v2 - viewport()
push.viewport()
grid.points(x[1],y[1],pch=16,gp=gpar(col='green'),name='pts')
index = tclVar(1)
grid
refresh - function(...){
  i - as.numeric(tclvalue(index))
  grid.edit('pts',x=unit(x[i],'npc'),y=unit(y[i],'npc'))

}
m - tktoplevel()
pScale - 
tkscale(m,from=0,to=1,orient='horiz',resolution=1,variable=index,command=refresh)
tkgrid(pScale)

The green point should change as the slider is moved, but there are so
many points in the background that replotting them confuses the
graphic.  What I want to be able to do is replt the green point
without removing the background.

Sam Stewart

On Wed, Sep 24, 2008 at 11:12 AM, Ben Bolker [EMAIL PROTECTED] wrote:
 R Help rhelp.stats at gmail.com writes:


 Hello list,

 I've been working on this problem for a while and I haven't been able
 to come up with a solution.

 I have a couple of functions that plot a bunch of data, then a single
 point on top of it.  What I want is to be able to change the plot of
 the point without replotting all the data.  Consider the following
 example:

 x = rnorm(100,1,0.5)
 y = rnorm(100,1,0.5)
 plot(x,y,pch=16)
 points(x[35],y[35],pch=19,col=6,cex=3)

 What I want to be able to do is to change the purple point to a
 different value without replotting everything.


  R's default (base) graphics model is a 'canvas' -- things get
 drawn, but nothing ever gets erased. (The cheap solution is
 to overplot in the background color, but that
 won't work if there's stuff underneath the point
 that you want to preserve.) You probably need to move
 to the grid graphics package (hint: buy or borrow Paul Murrell's
 book) to do something like this.

  Ben Bolker

 __
 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.


__
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.


Re: [R] Changing a plot

2008-09-25 Thread Peter Dalgaard
R Help wrote:
 Thanks, I looked into the grid package.  The grid package does do a
 better job of managing the plotting, but it's still re-plotting the
 entire canvas whenever a modifcation is made to a plot.

 I guess I should have been a little clearer with my question.  Here's
 a sample function.

 library(tcltk)
 x = runif(1)
 y = runif(1)
 v1 - viewport()
 grid.rect(gp = gpar(lty = dashed))
 pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
 pushViewport(dataViewport(x, y))
 grid.rect()
 grid.xaxis()
 grid.yaxis()
 grid.points(x, y)
 grid.text(1:10, x = unit(-3, lines), rot = 90)
 v2 - viewport()
 push.viewport()
 grid.points(x[1],y[1],pch=16,gp=gpar(col='green'),name='pts')
 index = tclVar(1)
 grid
 refresh - function(...){
   i - as.numeric(tclvalue(index))
   grid.edit('pts',x=unit(x[i],'npc'),y=unit(y[i],'npc'))

 }
 m - tktoplevel()
 pScale - 
 tkscale(m,from=0,to=1,orient='horiz',resolution=1,variable=index,command=refresh)
 tkgrid(pScale)

 The green point should change as the slider is moved, but there are so
 many points in the background that replotting them confuses the
 graphic.  What I want to be able to do is replt the green point
 without removing the background.

   
The TK canvas is rather good at replotting only what is necessary.
Unfortunately, it lacks functionality for a real graphics driver, but
you might want to look into demo(tkcanvas).



-- 
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
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.


Re: [R] Changing a plot

2008-09-25 Thread Ben Bolker
R Help wrote:
 Thanks, I looked into the grid package.  The grid package does do a
 better job of managing the plotting, but it's still re-plotting the
 entire canvas whenever a modifcation is made to a plot.
 
 I guess I should have been a little clearer with my question.  Here's
 a sample function.
 
 library(tcltk)
 x = runif(1)
 y = runif(1)
 v1 - viewport()
 grid.rect(gp = gpar(lty = dashed))
 pushViewport(plotViewport(c(5.1, 4.1, 4.1, 2.1)))
 pushViewport(dataViewport(x, y))
 grid.rect()
 grid.xaxis()
 grid.yaxis()
 grid.points(x, y)
 grid.text(1:10, x = unit(-3, lines), rot = 90)
 v2 - viewport()
 push.viewport()
 grid.points(x[1],y[1],pch=16,gp=gpar(col='green'),name='pts')
 index = tclVar(1)
 grid
 refresh - function(...){
   i - as.numeric(tclvalue(index))
   grid.edit('pts',x=unit(x[i],'npc'),y=unit(y[i],'npc'))
 
 }
 m - tktoplevel()
 pScale - 
 tkscale(m,from=0,to=1,orient='horiz',resolution=1,variable=index,command=refresh)
 tkgrid(pScale)
 
 The green point should change as the slider is moved, but there are so
 many points in the background that replotting them confuses the
 graphic.  What I want to be able to do is replt the green point
 without removing the background.
 
 Sam Stewart
 

  OK, I see the issue but I don't at the moment see a way around it.
  The only R graphics device I know of that actually maintains the full
scene in the way that you want is rgl:


library(rgl)
rgl.bg(color=white)
rgl.points(runif(1),runif(1),0,col=black)
rgl.viewpoint(theta=0,phi=0,fov=1)
for (i in 5:995) {
  ##  rgl.points(i/1000,i/1000,0,col=green,alpha=0.5,size=20)
  rgl.spheres(i/1000,i/1000,0,col=green,alpha=1,radius=0.02)
  rgl.pop()
}

  This is kind of an ugly workaround, but maybe it will work for you.
(Really, the fundamental problem is that the plot is ALWAYS being
redrawn -- I think the issue is that rgl just redraws it much faster ...)

   I'm curious if anyone else has solutions.

  Ben Bolker

__
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.


[R] Changing a plot

2008-09-24 Thread R Help
Hello list,

I've been working on this problem for a while and I haven't been able
to come up with a solution.

I have a couple of functions that plot a bunch of data, then a single
point on top of it.  What I want is to be able to change the plot of
the point without replotting all the data.  Consider the following
example:

x = rnorm(100,1,0.5)
y = rnorm(100,1,0.5)
plot(x,y,pch=16)
points(x[35],y[35],pch=19,col=6,cex=3)

What I want to be able to do is to change the purple point to a
different value without replotting everything.

I know this seems like an odd suggestion, but it comes up a lot with
the work I'm doing.  I've prepared a package on CRAN called
ResearchMethods for a course I'm working on, and there are several
functions in there who's GUIs could work better if I could figure this
out.

If anyone has any ideas, or needs some further explanation, feel free
to contact me.

Thanks a lot,
Sam Stewart

__
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.


Re: [R] Changing a plot

2008-09-24 Thread Ben Bolker
R Help rhelp.stats at gmail.com writes:

 
 Hello list,
 
 I've been working on this problem for a while and I haven't been able
 to come up with a solution.
 
 I have a couple of functions that plot a bunch of data, then a single
 point on top of it.  What I want is to be able to change the plot of
 the point without replotting all the data.  Consider the following
 example:
 
 x = rnorm(100,1,0.5)
 y = rnorm(100,1,0.5)
 plot(x,y,pch=16)
 points(x[35],y[35],pch=19,col=6,cex=3)
 
 What I want to be able to do is to change the purple point to a
 different value without replotting everything.
 

  R's default (base) graphics model is a 'canvas' -- things get
drawn, but nothing ever gets erased. (The cheap solution is
to overplot in the background color, but that 
won't work if there's stuff underneath the point
that you want to preserve.) You probably need to move
to the grid graphics package (hint: buy or borrow Paul Murrell's
book) to do something like this.

  Ben Bolker

__
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.


Re: [R] Changing a plot

2008-09-24 Thread Adaikalavan Ramasamy
One way is to keep a copy of the original and then return to it when you 
need it.


 x - rnorm(100,1,0.5)
 y - rnorm(100,1,0.5)
 plot(x,y,pch=16)
 original - recordPlot()

 for( i in 1:10 ){
   points( x[i], y[i], pch=19, col=yellow, cex=3)
   points( x[i], y[i], pch=16)
   Sys.sleep(1)  # slow the graphs a bit
   replayPlot(original)
 }

Regards, Adai



R Help wrote:

Hello list,

I've been working on this problem for a while and I haven't been able
to come up with a solution.

I have a couple of functions that plot a bunch of data, then a single
point on top of it.  What I want is to be able to change the plot of
the point without replotting all the data.  Consider the following
example:

x = rnorm(100,1,0.5)
y = rnorm(100,1,0.5)
plot(x,y,pch=16)
points(x[35],y[35],pch=19,col=6,cex=3)

What I want to be able to do is to change the purple point to a
different value without replotting everything.

I know this seems like an odd suggestion, but it comes up a lot with
the work I'm doing.  I've prepared a package on CRAN called
ResearchMethods for a course I'm working on, and there are several
functions in there who's GUIs could work better if I could figure this
out.

If anyone has any ideas, or needs some further explanation, feel free
to contact me.

Thanks a lot,
Sam Stewart

__
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.


__
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.


[R] Changing default plot behaviour

2008-04-09 Thread Thompson, David (MNR)
Hello,

How would I make the default behaviour of my plots produce output such
as the following (i.e. tick marks inside on all axes, labels only on two
(arbitrary?) sides) without needing the five additional commands each
time?

plot(1:10, axes=FALSE)
axis(1, tcl=0.5)
axis(2, tcl=0.5)
axis(3, tcl=0.5, labels=FALSE)
axis(4, tcl=0.5, labels=FALSE)
box()

Thanx, DaveT.
*
Silviculture Data Analyst
Ontario Forest Research Institute
Ontario Ministry of Natural Resources
[EMAIL PROTECTED]
http://ofri.mnr.gov.on.ca

__
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.


Re: [R] Changing default plot behaviour

2008-04-09 Thread Richard . Cotton
 How would I make the default behaviour of my plots produce output such
 as the following (i.e. tick marks inside on all axes, labels only on two
 (arbitrary?) sides) without needing the five additional commands each
 time?
 
 plot(1:10, axes=FALSE)
 axis(1, tcl=0.5)
 axis(2, tcl=0.5)
 axis(3, tcl=0.5, labels=FALSE)
 axis(4, tcl=0.5, labels=FALSE)
 box()

Use a custom plotting function, e.g.
myplot - function(..., sidesforlabels)
{
   #sidesforlabels should be a numeric vector containing the sides that 
you want labels on
   plot(..., axes=FALSE)
   par(tcl=0.5)
   for(i in 1:4)
   {
  axis(i, labels=i %in% sidesforlabels)
   }
   box()
}

myplot(1:10, sidesforlabels=1:2)

Regards,
Richie.

Mathematical Sciences Unit
HSL



ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

__
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.


Re: [R] Changing default plot behaviour

2008-04-09 Thread hadley wickham
On Wed, Apr 9, 2008 at 10:12 AM, Thompson, David (MNR)
[EMAIL PROTECTED] wrote:
 Hello,

  How would I make the default behaviour of my plots produce output such
  as the following (i.e. tick marks inside on all axes, labels only on two
  (arbitrary?) sides) without needing the five additional commands each
  time?

It's generally not a very good idea to put the tick marks inside the
plot (as e.g. matlab does) because sometimes your data and tick marks
will overlap - not good!

Hadley

-- 
http://had.co.nz/

__
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.


Re: [R] Changing default plot behaviour

2008-04-09 Thread John Kane
This may be a bit simple minded but why not change
those commmands into a single function something like
this and run it rather than the actual plot command?

myfunction - function(a) {
plot(a, axes=FALSE)
 axis(1, tcl=0.5)
 axis(2, tcl=0.5)
 axis(3, tcl=0.5, labels=FALSE)
 axis(4, tcl=0.5, labels=FALSE)
 box()
}


--- Thompson, David (MNR)
[EMAIL PROTECTED] wrote:

 Hello,
 
 How would I make the default behaviour of my plots
 produce output such
 as the following (i.e. tick marks inside on all
 axes, labels only on two
 (arbitrary?) sides) without needing the five
 additional commands each
 time?
 
 plot(1:10, axes=FALSE)
 axis(1, tcl=0.5)
 axis(2, tcl=0.5)
 axis(3, tcl=0.5, labels=FALSE)
 axis(4, tcl=0.5, labels=FALSE)
 box()
 
 Thanx, DaveT.
 *
 Silviculture Data Analyst
 Ontario Forest Research Institute
 Ontario Ministry of Natural Resources
 [EMAIL PROTECTED]
 http://ofri.mnr.gov.on.ca
 
 __
 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.
 



  __
[[elided Yahoo spam]]

__
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.


Re: [R] Changing default plot behaviour

2008-04-09 Thread Thompson, David (MNR)
Thank you all for your help.
I successfully used Richard's suggestion (much like John's) and
continued with my work, neglecting to respond to the list.
Sorry about that.

Thanx again, DaveT.
-Original Message-
From: John Kane [mailto:[EMAIL PROTECTED] 
Sent: April 9, 2008 03:16 PM
To: Thompson, David (MNR); r-help@r-project.org
Subject: Re: [R] Changing default plot behaviour

This may be a bit simple minded but why not change
those commmands into a single function something like
this and run it rather than the actual plot command?

myfunction - function(a) {
plot(a, axes=FALSE)
 axis(1, tcl=0.5)
 axis(2, tcl=0.5)
 axis(3, tcl=0.5, labels=FALSE)
 axis(4, tcl=0.5, labels=FALSE)
 box()
}


--- Thompson, David (MNR)
[EMAIL PROTECTED] wrote:

 Hello,
 
 How would I make the default behaviour of my plots
 produce output such
 as the following (i.e. tick marks inside on all
 axes, labels only on two
 (arbitrary?) sides) without needing the five
 additional commands each
 time?
 
 plot(1:10, axes=FALSE)
 axis(1, tcl=0.5)
 axis(2, tcl=0.5)
 axis(3, tcl=0.5, labels=FALSE)
 axis(4, tcl=0.5, labels=FALSE)
 box()
 
 Thanx, DaveT.
 *
 Silviculture Data Analyst
 Ontario Forest Research Institute
 Ontario Ministry of Natural Resources
 [EMAIL PROTECTED]
 http://ofri.mnr.gov.on.ca
 
 __
 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.
 



  
__
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/


__
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.