【问题标题】:Why connects geom_line not to next point when using in gganimate?为什么在 gganimate 中使用 geom_line 不连接到下一个点?
【发布时间】:2019-03-07 01:05:00
【问题描述】:

当我有这个数据框时

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)

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

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

【问题讨论】:

    标签: gganimate


    【解决方案1】:

    transition_reveal() 
    

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

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

    试试:

    ggplot(data, aes(year, num))+
      geom_point()+
      geom_line()+
      transition_reveal(1, year)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 1970-01-01
      • 2014-06-27
      相关资源
      最近更新 更多