为什么在 gganimate 中使用时连接 geom_line 而不是下一个点?
Why connects geom_line not to next point when using in gganimate?
当我有这个数据框时
library(ggplot)
library(gganimate)
data <- tribble(
~year, ~num,
1950, 56,
1951, 59,
1952, 64,
1953, 76,
1954, 69,
1955, 74,
1956, 78,
1957, 98,
1958, 85,
1959, 88,
1960, 91,
1961, 87,
1962, 99,
1963, 104
)
并想用 gganimate 制作动画线图:
ggplot(data, aes(year, num))+geom_point()+geom_line()+transition_reveal(year, num)
我得到一张图表,其中点和线的绘制顺序错误。
这是什么原因,我该如何纠正?
在
transition_reveal()
第一个参数 (id) 关于群体审美(你没有)。我发现仅对单个时间序列使用 id = 1 即可。
第二个参数(沿)应该是你的 x 美学(在你的情况下是年份)。
尝试:
ggplot(data, aes(year, num))+
geom_point()+
geom_line()+
transition_reveal(1, year)
当我有这个数据框时
library(ggplot)
library(gganimate)
data <- tribble(
~year, ~num,
1950, 56,
1951, 59,
1952, 64,
1953, 76,
1954, 69,
1955, 74,
1956, 78,
1957, 98,
1958, 85,
1959, 88,
1960, 91,
1961, 87,
1962, 99,
1963, 104
)
并想用 gganimate 制作动画线图:
ggplot(data, aes(year, num))+geom_point()+geom_line()+transition_reveal(year, num)
我得到一张图表,其中点和线的绘制顺序错误。
这是什么原因,我该如何纠正?
在
transition_reveal()
第一个参数 (id) 关于群体审美(你没有)。我发现仅对单个时间序列使用 id = 1 即可。
第二个参数(沿)应该是你的 x 美学(在你的情况下是年份)。
尝试:
ggplot(data, aes(year, num))+
geom_point()+
geom_line()+
transition_reveal(1, year)