结合使用 ggplot2 和 rpanel

发布于 2024-08-17 19:13:53 字数 559 浏览 1 评论 0原文

有没有人使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掀纱窥君容 2024-08-24 19:13:53

不幸的是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文