admin管理员组

文章数量:1200396

I have been attempting to animate animal tracking data using the archived package Movevis. Unfortunately, Movevis is an archived and outdated package, so I've had to get creative with some of my solutions. One of them has been to manually insert the basemap layer because the basemap satellite layer that comes built in with the package is low quality and prone to visual errors. Unfortunately, as a result of this it appears that my base map layer for whatever reason is shifted slightly to the right of where it should be.

My example code below uses a dataset and code from the Movevis package. For ease of workflow, I've replaced the original mapbox satellite map with an osm street map that does not require a token. I am currently able to replace the original base map with a new base map, as you can see from my combined.plot figure. My question is, is there any way to nudge my new base map slightly to the right until the base map aligns with my tracking data? I thought the gginnards package might be able to help, but have so far found nothing in it. Thanks!

#load packages
library(devtools)
library(pkgbuild)
library(gginnards)
library(ggspatial)
library(ggmap)
#installing Movevis
install_url('.10.5.tar.gz') #moveVis
library(moveVis)
library(move)

#read in example data
data("move_data")

# align movement to unique times and regular resolution
m <- align_move(move_data, res = 4, unit = "mins")
ext<-extent(m)

## assign some path colours by individual
m.list <- split(m) # split m into list by individual
m.list <- mapply(x = m.list, y = c("red", "green", "blue"), function(x, y){
  x$colour <- y
  return(x)
}) # add colour per individual
m <- moveStack(m.list) # putting it back together into a moveStack

# create frames with mapbox satellite basemap (osm streets map in this example to avoid token issues and allow for reproduceability)
frames <- frames_spatial(m, map_service = "osm", map_type = "streets")

#draw out single frame from animation to use as example
example<-frames[[95]]
example #example showing incorrect original satellite layer

#remove base layer from example frame
example<-delete_layers(example, "GeomRaster")
example

#create new base layer using google satellite imagery
ggmap::register_google(key = "YOUR KEY HERE")
base<-get_map(c(left = ext[1]-.02, bottom = ext[3]-.01, right = ext[2]+.02, top = ext[4]+.01),
              source="google",maptype="satellite")
base<-ggmap(base)
base

#combine example frame and new base map
combined.plot<-append_layers(example,base$layers[[2]],position="bottom")
combined.plot #great, now is there any way I can nudge that basemap slightly to the left for my purposes?

本文标签: rHow to Nudge a ggplot Basemap to the RightStack Overflow