tags:

views:

157

answers:

1

Has anybody used ggplot2 along with rpanel to produce interactive plots. Here is a piece of code that I adapted from rpanel to plot a Poisson distribution and have a slider to change the parameter value.

However, the plot changes too slowly as I change the parameters using the slider. When I change the plot function to use Lattice, it is much faster. Is this a limitation of ggplot2 in terms of speed? Is there a way to overcome this?

poisson.draw = function(panel) {
  with(panel, {
     x = seq(0,n, by = 1)
     library(ggplot2)
     y = dpois(x, lambda)
     d = data.frame(cbind(x,y))
     p1 = ggplot(d, aes(x,y)) + geom_point()
     print(p1)
  })
  panel
}
panel <- rp.control("Poisson distribution", n = 30, lambda = 3, 
  ylim = 0.5)
rp.slider(panel, lambda, 1, 30, poisson.draw)
+1  A: 

Unfortunately ggplot2 is slow at the moment. However, I have received a generous donation that will allow me to work on performance over summer, so I hope it will be substantially improved.

hadley
Thanks for the response Hadley. I will look forward to ggplot2 getting faster.
Ramnath