1

example map [ https://i.stack.imgur.com/7TfSo.gif ]

I have a map animation of a bird's yearly abundance which goes through a series of years. I want to add an inset graph of the trend in the birds' abundance, a line to show the trend and a dot that moves along through each year corresponding to the year on the map. I've managed to create the graph and the map as animations separately but I don't know how to animate them together. I'm using the old version of gganimate. I've attached the map so far, without the point moving.

Does anyone know how I can animate the point on the inset map, too?

The map dataset looks similar to this:

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

The code for the map:

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)

Sample data for the inset map:

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

The code for my inset map is:

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)
  • 1
    Hi Jenni, welcome to Stackoverflow. Thank you for posting your code and your output. Unfortunately, your code is [neither minimal, nor reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Could you provide a minimal dataset? – Roman Nov 09 '18 at 18:03
  • Hi. sorry I'm not very experienced at posting questions on here, simplied the code and try to add some example data but it's tricky with a map as the file is quite long. Can I upload test data files somehow? – Jennifer Taylor Nov 10 '18 at 16:27

0 Answers0