【问题标题】:How to render ggplot2+gganimate+ggflags faster如何更快地渲染 ggplot2+gganimate+ggflags
【发布时间】:2019-12-01 07:42:48
【问题描述】:

我正在使用 ggplot2+gganimate+ggflags 进行绘图,但它的渲染速度非常慢:通常每秒或小于 0.1 帧。因此,如果我有 300 帧,则需要很长时间。我注意到是 ggflags 导致它变得比其他方式慢得多。我能做些什么来加快渲染速度吗?我使用的是 MacBook Pro。

我的基本代码设置如下所示:

plot <- data %>% ggplot2(aes(...)) + geom_flag(...) + lots of options + transition_time(year) 

anim_save("file.gif", plot, ...)

【问题讨论】:

标签: r ggplot2 render gganimate


【解决方案1】:

如果没有具体的例子,很难明确回答。

当我运行以下命令时,它会在我的 2012 macbook air 上产生大约 3.5 fps 的速度。用geom_point 代替geom_flag,它产生大约4.5 fps。考虑到标志的绘制更加复杂,这并没有让我觉得减速特别大。您是否有其他选项或很多标志可能会使其变慢?

library(tidyverse)
library(ggflags)  # Using v0.0.1 downloaded 11/30/19 from 
                  #    https://github.com/ellisp/ggflags  
library(gganimate)
library(gapminder)

animate(
  gapminder %>% 
  filter(continent == "Asia") %>%
  ggplot(aes(gdpPercap, lifeExp, country = country)) + 
  geom_flag() +
  transition_time(year),
  width = 700, height = 400, fps = 20)

【讨论】:

  • 疯狂动态的红黄旗是什么?
  • 科威特:library(plotly); gg0 &lt;- gapminder %&gt;% filter(continent=="Asia") %&gt;% ggplot(aes(x=year,y=gdpPercap,colour=country))+geom_line(); ggplotly(gg0)
  • 谢谢。碰巧的是,我的实际应用程序与您的示例非常相似。我尝试按原样运行您的代码。一个区别是我的 ggflags 似乎有所不同,因为我使用了圆形标志(请参阅github.com/rensa/ggflags)。另一个是我使用anim_save 而不是animate。我也有更多的国家和更多的岁月。但是按照你的方式运行代码(使用不同的 ggflags),我仍然得到一个非常慢的结果:0.43 fps。如果我摆脱亚洲限制,这将下降到每秒 0.12 帧。
  • 看起来 rensa 版本的 ggflags 使用 grImport2 来加载和渲染 SVG 图像;原来使用grid::raster()。我相信这会有所作为。
  • 也许@JonSpring(或某人)可以对这两个包进行并排比较...
猜你喜欢
  • 2019-12-16
  • 1970-01-01
  • 2013-10-04
  • 2013-12-07
  • 1970-01-01
  • 2017-07-28
  • 1970-01-01
  • 2020-11-12
  • 2018-08-07
相关资源
最近更新 更多