1
I’m using this Shape file to make a map: link
library(rgdal)
library(ggplot2)
mapadf <- readOGR(dsn= "/rj_municipios", layer = "33MUE250GC_SIR")
mapadf <-fortify(mapadf)
The map stays as I want, so I try to put the scale using package ggsn
library(ggsn)
country3 <-ggplot(data= mapadf, aes(x=long, y=lat, group=group)) +
geom_path() +
coord_map("mercator") +
xlim(-42.040,-41.973)+
ylim(-23.015, -22.94)
country3+ ggsn:: scalebar(mapadf,x.min = -42.040, x.max = -41.973,
y.min = -23.015, y.max = -22.94,
dist=5, model='WGS84',
st.dist=.05, transform = TRUE,
dist_unit = "Km")
Then I get:
Error in maptools::gcDestination(lon = x, lat = y, bearing = 90 * direction, :
subscript out of bounds
Warning message:
Removed 3 rows containing missing values (geom_text)
I’ve seen it work on all the examples I find, with me it doesn’t work, someone can help me?
I have no way to test at the moment, but try removing
xlim()
andylim()
of the map and x min., x max., y. min and y. max ofscalebar()
.– Carlos Eduardo Lagosta
By doing this I lose the location of the map I want to show.
– Nevs Bia