繁体   English   中英

如何在 RStudio 查看器中更改动画图 (gif) 的分辨率?

[英]How to change the resolution of animated plots (gif) in RStudio Viewer?

我目前正在按照教程学习使用gganimate库创建动画图。

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

我的查看器中的 animation:

RStudio 查看器中的输出

来自网站的相同动画 plot 的外观: gganimate 教程中的示例

从网站上创建上述动画 plot 的代码:

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

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

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

在此处此处查看我的相关答案。

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

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)

结果

在这种情况下,还要检查这篇文章library(ragg)并设置animate的参数device = 'ragg_png'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM