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)