将gganimate的view_follow函数与静态位一起使用

时间:2019-10-05 14:21:25

标签: r ggplot2 gganimate

按照wiki中设置的示例,我想使用view_follow函数静态点/线/标签创建动画。

问题在于,只有在查看静态线/标签后,view_follow才能按预期工作。

library(gganimate)

airq <- airquality
airq$Month <- format(ISOdate(2004,1:12,1),"%B")[airq$Month]

# modified code 
ggplot(airq, aes(Day, Temp, group = Month)) + 
  geom_line() + 
  geom_segment(aes(xend = Day+1, yend = Temp), linetype = 2, colour = 'grey') + 
  geom_point(size = 2) + 
  geom_text(aes(x = Day+1.1, label = Month), hjust = 0) + 
  transition_reveal(Day) + 
  coord_cartesian(clip = 'off') + 
  labs(title = 'Temperature in New York', y = 'Temperature (°F)') + 
  theme_minimal() + 
  theme(plot.margin = margin(5.5, 40, 5.5, 5.5))+
  view_follow(aspect_ratio = (16/9))+ # add view_follow()
  geom_vline(xintercept = 15)+ #added static point
  geom_label(aes(x = 15, y = 45, label = "text"), hjust = 1) #add a label

所需的行为是使行和标签“出现在视图中”。我该如何完成?

0 个答案:

没有答案