Skip to content

Plot availability

8 messages · john crepezzi, Duncan Murdoch, Hadley Wickham +1 more

#
On 9/19/2008 9:32 AM, john crepezzi wrote:
I don't think so.  You can see if a graphics device is open by looking 
at dev.cur(), but I don't think there's a test for plot.new().  I'd just 
wrap the call in try() if you're not sure it will work.

Duncan Murdoch
#
I'm not so sure the original way I stated my issue was clear enough,
so I'll attempt to elaborate a little bit.

I'd like to make a function that is passed the name of a plot object,
and a lines/point specification, and graphs them all on the same plot.

I don't want to redraw the plot each time, and I don't want the code
to have any concept of a "first entry" instantiating the plot with
plot() in place of lines().

Ideally, I'd like something to the effect of:

plot <- createPlot(main = "Hello World", sub = "tiny, little world",
xlim = c(-3, 3), ylim = c(-3, 3))

plot <- addElement(plot, lines(col = 'BLUE', x = c(0, 1, 2, 3), y =
c(3, 2, 1, 0)))

Hopefully this laid my problem out a little better.

Thanks in advance for any help you might be able to offer
-John Crepezzi
On Sep 19, 10:11?am, Duncan Murdoch <murd... at stats.uwo.ca> wrote:
#
I believe I've found a way to wrap and use dev.cur()[[1]] to have the
desired effect.  I'm just leaving my terminal now, but I'll post these
results on monday so everyone can see how it turned out.

If you have any ideas or qualms with this method, please let me
know.

Thanks Duncan!
--john
On Sep 19, 2:00?pm, john crepezzi <seejohn... at gmail.com> wrote:
#
On Fri, Sep 19, 2008 at 1:00 PM, john crepezzi <seejohnrun at gmail.com> wrote:
Have a look at the ggplot2 package, which is based around this
concept:  http://had.co.nz/ggplot2.

Hadley
#
On Fri, Sep 19, 2008 at 2:00 PM, john crepezzi <seejohnrun at gmail.com> wrote:
Using classic graphics try this:

# classic graphics
plot(BOD)
p <- recordPlot()

# some times go by and other plots are made
plot(0)

# now go back to the original plot and add more
replayPlot(p)
points(5, 15, col = "red")


In lattice graphics its like this:

# lattice graphics
library(lattice)
p <- xyplot(demand ~ Time, BOD)

# some times go by and other plots are made
plot(0)

# now replot the original plot and add more
plot(p)
trellis.focus("panel", 1, 1)
panel.points(5, 15, col = "red")
trellis.unfocus()

ggplot2 is also grid-based and should be amenable to
this sort of thing too.
#
I really would encourage you to look at ggplot2 before trying to
create something of your own.  Your example would convert to the
following ggplot2 code:

df <- data.frame(x = 0:3, y = 3:0)

plot <- ggplot() + xlim(-3, 3) + ylim(-3, 3) + opts(main = "Hello World")
plot + geom_line(aes(x=x, y=y), df, colour = "blue")

Hadley
On Fri, Sep 19, 2008 at 1:44 PM, john crepezzi <seejohnrun at gmail.com> wrote:

  
    
#
hadley,
thanks for the example, that put it much better into perspective.  I'm
gonna make some coffee and read through this page and see how deep it
goes.  I might even be able to use this for some other things we're
doing.

Thanks!
--John Crepezzi
hadley wickham wrote: