0

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')

Example map

ljh2001
  • 391
  • 3
  • 17
  • 1
    According to [this](https://www.worldatlas.com/maps/united-states) the widest width of the US is 4,500 km. Also beware of using scale bars on maps at this scale: https://stackoverflow.com/a/41373569/12400385 – nniloc Apr 27 '21 at 21:50
  • @nniloc Yes.. good point, thanks for the reminder! – ljh2001 Apr 27 '21 at 22:17

0 Answers0