【问题标题】:How to change the resolution of animated plots (gif) in RStudio Viewer?如何在 RStudio Viewer 中更改动画图 (gif) 的分辨率?
【发布时间】:2022-01-26 20:00:42
【问题描述】:

我目前正在关注this 教程,学习使用gganimate 库创建动画情节。

但是,我已经在为第一个动画而苦苦挣扎。虽然动画本身有效,但与网站上的示例相比,它的分辨率有所降低。在 RStudio 中调整“查看器”的大小不会改变尺寸/分辨率。绘制没有动画的图像 (plot(p)) 在“绘图”中创建一个绘图,其尺寸和分辨率与网站上的绘图相同。我需要调整查看器的一些设置吗?我正在使用 Windows 10、RStudio 版本 1.4.1717、R 版本 4.1.1。

我的观众的动画:

来自网站的相同动画情节的外观:

来自网站的用于创建上述动画情节的代码:

library(gganimate)
p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + 
  geom_point()
anim <- p + 
  transition_states(Species,
                    transition_length = 2,
                    state_length = 1)
anim

【问题讨论】:

    标签: r ggplot2 rstudio gganimate


    【解决方案1】:

    我猜 gganimate 文章中显示的那些图是在 Linux 平台上创建的。 gganimate 默认使用 'png' 设备来渲染单帧。

    png() 在 Windows 上默认使用Windows GDI,这在 Linux 上不可用(使用 cairographics)。这就是(可能)结果不同的原因。

    请看我的相关回答herehere

    要在 Windows 上获得(或多或少)相同的输出,您可以执行以下操作:

    library(gganimate)
    library(gifski)
    
    p <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) +
      geom_point()
    anim <- p +
      transition_states(Species,
                        transition_length = 2,
                        state_length = 1)
    myAnimation <- animate(anim, duration = 3.3, fps = 10, width = 1400, height = 865, renderer = gifski_renderer(), res = 200, type = "cairo")
    anim_save("test.gif", animation = myAnimation)
    

    在这种情况下,还要检查this articlelibrary(ragg) 和设置animate 的参数device = 'ragg_png'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 2020-10-23
      • 2020-07-14
      • 1970-01-01
      相关资源
      最近更新 更多