gpt4 book ai didi

r - 如何固定 gganimate 中绘图的宽度?

转载 作者:行者123 更新时间:2023-12-04 15:42:20 26 4
gpt4 key购买 nike

我在设置动画时无法设置绘图的宽度。

因此,如果我使用库 gapminder 制作静态图,代码如下:

library(ggplot2)
library(gganimate)
theme_set(theme_bw())
library(gapminder)

p <- ggplot(
gapminder,
aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)
) +
geom_point(show.legend = FALSE, alpha = 0.7) +
scale_color_viridis_d() +
scale_size(range = c(2, 12)) +
scale_x_log10() +
labs(x = "GDP per capita", y = "Life expectancy")
p

它使绘图占满整个窗口的宽度,就像我期望的那样。但是如果我添加过渡:

p + transition_time(year) +
labs(title = "Year: {frame_time}")

它使图的宽度大约减少了一半。

有没有办法让它成为动画的全宽?

最佳答案

您只需调整绘图的高度宽度,您可以使用animate稍微调整最后一部分你的代码:

p <- p + transition_time(year) +
labs(title = "Year: {frame_time}")
animate(p, height = 461, width = 644)

heightwidth 选择的数字在我的 RStudio 中显示为默认值,因此您可能需要将它们调整为您想要的任何值。

关于r - 如何固定 gganimate 中绘图的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57388625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com