[英]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:
从网站上创建上述动画 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.