结合使用 ggplot2 和 rpanel
有没有人使用 ggplot2 和 rpanel 来生成交互式绘图。这是我从 rpanel 改编的一段代码,用于绘制泊松分布,并有一个滑块来更改参数值。
然而,当我使用滑块更改参数时,绘图变化太慢。当我将绘图函数更改为使用 Lattice 时,速度要快得多。这是 ggplot2 在速度方面的限制吗?有办法克服这个问题吗?
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)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是 ggplot2 目前速度很慢。不过,我收到了一笔慷慨的捐款,可以让我在夏天继续提高表现,所以我希望它能得到实质性的改善。
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.