Closed marcos-lee closed 5 years ago
Define x_lim and y_lim within the bounding box.
x_lim <- map_saosebast$data[c(1, 4), 1] * c(.9998, 1.003)
y_lim <- map_saosebast$data[c(1, 4), 2] * c(.9998, 1.003)
Thank you, this works.
However, the bounding box values seems to change according to the amount of zoom I use in the get_googlemap function, e.g.:
map_saosebast <- ggmap(get_googlemap("sao sebastiao, sp, brazil",
scale = 2, zoom = 13,
maptype ='terrain',
color = 'color'))
x_lim <- map_saosebast$data[c(1, 4), 1] * c(.9998, 1.003)
y_lim <- map_saosebast$data[c(1, 4), 2] * c(.9998, 1.003)
map_saosebast + scalebar(x.min = x_lim[1], x.max = x_lim[2],
y.min = y_lim[1], y.max = y_lim[2],
dist = 1, dist_unit = 'km', transform = TRUE, model = 'WGS84')
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: Removed 2 rows containing missing values (geom_text).
In the example above, it fails, but if I change the bounding box multiple to x_lim <- map_saosebast$data[c(1, 4), 1] * c(.99998, 1.0003)
then it works.
Is there maybe a more systematic way of doing this?
Maybe but I have no thought in that so far. If you find one let me know.
Map plots, but no scalebar. Using the values by hand in x.min, etc, produces the same error.