首页 > 解决方案 > 如何将回归线添加到 gganimate 图中?

问题描述

我想在我的 gganimate 图中添加一条回归线。如果没有回归线,gganimate 绘图按预期工作,当我将 geom_smooth 命令添加到常规绘图时,它工作正常。当我尝试将回归线添加到 gganimate 图中时,我只会收到错误消息。

g <- ggplot(pdata, aes(x = ole, y = rsv)) + 
        geom_point(aes(color = region)) + 
        geom_smooth(aes(group = region, color = region), se = FALSE)

anim <- g + transition_states(region, transition_length = 3, state_length = 5) 
anim

我收到错误消息:

 geom_smooth()` using method = 'loess' and formula 'y ~ x'
`geom_smooth()` using method = 'loess' and formula 'y ~ x'
Error in transform_path(all_frames, next_state, ease, params$transition_length[i],  : 
  transformr is required to tween paths and lines

标签: rggplot2data-visualizationgganimate

解决方案


推荐阅读