1

示例地图 [ https://i.stack.imgur.com/7TfSo.gif ]

我有一个鸟类每年丰富的地图动画,它经历了一系列年份。我想添加鸟类丰度趋势的插图,显示趋势的线和对应于地图上年份的每年移动的点。我已经设法将图形和地图分别创建为动画,但我不知道如何将它们动画在一起。我正在使用旧版本的 gganimate。到目前为止,我已经附上了地图,没有移动点。

有谁知道我也可以为插图上的点设置动画吗?

地图数据集如下所示:

easting northing  yr    pred
168500    16500 1994  8.565071
168500    16500 1995  8.944672
168500    16500 1996  9.324085
168500    16500 1997  9.682163
168500    16500 1998  9.991015
168500    16500 1999 10.216780
168500    16500 2000 10.327187

地图代码:

my_plot<-ggplot()+
geom_point(data=test_map_data,aes(x=easting, y=northing, frame=yr, 
colour=pred), size=0.8)+
coord_quickmap()+
theme_bw() +
theme(panel.grid.major = element_blank(),
      panel.grid.minor = element_blank(),
      panel.border = element_blank(),
      panel.background = element_blank(),
      axis.line=element_blank(),
      axis.ticks=element_blank(),
      axis.title.x=element_blank(),
      axis.title.y=element_blank(),
      axis.text =element_blank())

#Add on trend graph
x <- my_plot + annotation_custom(grob=inset_plot, xmin=-305000, 
xmax=70000, ymin=630000, ymax=1200000)
gganimate(x, interval=0.5,file="trial.gif", ani.width=600, ani.height=700)

插图的样本数据:

test_inset<-data.frame(years=1994:2000, trend=c(1,1.2,1.27, 
1.16,0.97,0.85,0.83))

我的插图的代码是:

m<-ggplot()+geom_line(data=test_inset, aes(x=years, y=trend, group=1))+
   theme_bw()+geom_point(data=trend_graph_sp, aes(x=years, y=trend, 
   frame=years, group=1), size=2, colour="#2b8cbe")+
   xlab("Years")+ylab("Trend")+
   scale_x_continuous(breaks=c(1995,2000,2005))+
   theme(axis.text.x = element_text(angle=90))+
   theme(panel.grid.major = element_blank(),
   panel.grid.minor = element_blank(),
   panel.border = element_blank(),
   panel.background = element_blank(), 
   axis.line=element_line(colour="black"))
   inset_plot<-ggplotGrob(m)
4

0 回答 0