oswaldosantos / ggsn

R package to add north symbols and scale bars to maps created with ggplot or ggmap
http://oswaldosantos.github.io/ggsn/
GNU General Public License v2.0
161 stars 9 forks source link

Scalebar but no text on scaled up map #41

Closed argrod closed 5 years ago

argrod commented 6 years ago

Hello, I have generated a map in ggplot, but plotted only the area between two sets of coordinates and would like to apply a scalebar. Using the x.min x.max etc. commands, the scale bar does appear, however no text appears. The warning message "Removed 3 rows containing missing values (geom_text)." appears whenever my code is run.

Below is an example, apologies if it is not suitable. Please let me know if there are any issues with it:

`install.packages('mapdata','maps','maptools') devtools::install_github("dkahle/ggmap") library(ggplot2) library(ggmap) library(maptools) library(maps) library(mapdata) library(ggsn)

japan <- map_data('japan')

JapanMap <- ggplot() + geom_polygon(data = japan, aes(x = long, y = lat, group = group)) + xlim(c(138, 144)) + ylim(c(35, 42)) + scalebar(x.min = 138, x.max = 144, y.min = 35, y.max = 42, dist = 50, dd2km = T, model = 'WGS84', location = 'bottomright', anchor = c(x = 144, y = 35, st.size = 3))`

Attached is the resultant map with scalebar but missing text scalebarnotext

Many thanks,

Aran

oswaldosantos commented 6 years ago

Hi Aran, Use y.min = 34 instead of y.min = 35. With 35, the lower y limit isn't lower enough to allow the inclusion of the scale bar text.

argrod commented 5 years ago

Thank you very much!