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 unusual behavior #18

Closed lwasser closed 7 years ago

lwasser commented 7 years ago

Hi there! i'm noticing some unusual behaviour with the scalebar function and wondered if you had seen this before.

odd-scalebar-behaviour

My code is here

# plot ggplot
ggplot() +
  geom_polygon(data = study_area_df, aes(x = long, y = lat, group = group),
               fill = "white", color = "black") +
  geom_path(data = sjer_roads_df, aes(x = long, y = lat,
                                      group = group, size = factor(RTTYP)), colour = "grey") +
  scale_size_manual("Road Type", values = c("M" = .3,
                                            "S" = .8,
                                            "Unknown" = .3)) +
  geom_point(data = sjer_plots_df, aes(x = coords.x1,
                                       y = coords.x2, shape = factor(plot_type), color = factor(plot_type)), size = 3) +
  scale_color_manual("Plot Type", values = c("trees" = "darkgreen",
                                 "grass" = "darkgreen",
                                 "soil" = "brown")) +
  scale_shape_manual("Plot Type", values = c("grass" = 18,
                                             "soil" = 15,
                                             "trees" = 8)) +
  labs(title = "ggplot() map of roads, plots and study area",
       subtitle = "with north arrow and scale bar",
       x = "", y = "") + ggsn::blank() +
  ggsn::scalebar(sjer_plots_df, dist = 100, dd2km = FALSE, model = 'WGS84', location = "topright",
                 st.dist = 10, st.size= 10,
                 anchor = c(x = x_scale_loc, y = y_scale_loc))

and the full tutorial is here: https://earthdatascience.org/course-materials/earth-analytics/week-4/r-make-maps-with-ggplot-in-R/

this is for my students. am i doing something wrong ? i'm getting characters for the scale bar and no bar. i presume i'm doing something wrong but can't seem to figure out what! my data are in UTM meters. Thank you for any help.

oswaldosantos commented 7 years ago

Hi, Try a smaller distance (e.g. 500m) to draw a scale bar within the bbox. Furthermore, I found a bug in dd2km. If dd2km is not to be equal to TRUE, either omit it or install the development version to use dd2km = FALSE.

# With the current version
ggsn::scalebar(data = study_area_df, dist = .5, model = "WGS84",
                         st.dist = .03, st.size = 5, height = .03)

# With the development version
ggsn::scalebar(data = study_area_df, dist = .5, model = "WGS84",
                         dd2km = FALSE, st.dist = .03, st.size = 5, height = .03)
lwasser commented 7 years ago

ok - thank you so much @oswaldosantos i was wondering about this because i did try to set dd2km to FALSE but it was insisting i add the datum/ellipsoid model which the documentation says i didn't need for projected m vs lat / lon geographic. this solution to remove the dd2km argument works wonderfully! thank you again. I am closing this issue 👍