I am trying to create a simple map with a scale bar using ggmap
and the developer version ofggsn
. The map seems to load well, but the scale bar measurements seem off. It shouldn't be over 4,000 km from coast to coast in the US. Below is my current code.
##installing packages.. not all are needed
library(tidyverse)
library(ggplot2)
library(sf)
library(ggspatial)
library(devtools)
library(ggmap)
library(maptools)
library(maps)
library(magick)
library(VTrack)
library(cowplot)
library(gridExtra)
## register a google api key
ggmap::register_google(key = "")
##creating the base map
inset <- get_googlemap(center = c(lon = -90, lat = 50), zoom = 3, maptype = "satellite",color = 'bw')
##below just makes the map a little lighter
insetx <- inset
inset_attributes <- attributes(insetx)
inset_transparent <- matrix(adjustcolor(insetx,
alpha.f = 0.9),
nrow = nrow(inset))
attributes(inset_transparent) <- inset_attributes
##installing dev version of ggsn
devtools::install_github('oswaldosantos/ggsn')
##combining the map with the scale bar. Note that scale bar appears to be off.
ggmap(inset_transparent)+
ggsn::scalebar(x.min = -180, x.max = -100,
y.min = 10, y.max = 85,
dist = 2000, transform = TRUE, dist_unit = 'km', model = 'WGS84',
box.fill = c('black', 'black'), st.color = 'white', box.color = 'white')