0

当我有这个数据框

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)

我得到一个图表,其中点和线以错误的顺序绘制。

在此处输入图像描述

这是什么原因,我该如何纠正?

4

1 回答 1

1

transition_reveal() 

第一个参数(id)与群体审美(你没有)有关。我发现仅对单个时间序列使用 id = 1 即可。

第二个论点(沿)应该是您的 x 审美(在您的情况下是年份)。

尝试:

ggplot(data, aes(year, num))+
  geom_point()+
  geom_line()+
  transition_reveal(1, year)
于 2018-10-05T00:12:54.440 回答