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

Compatibility with gganimate #44

Closed famuvie closed 5 years ago

famuvie commented 5 years ago

Hi there. First of all, thanks for the package.

I just wanted to point out an issue with the package gganimate. While the scale bar works fine for static plots, for some reason it gives problems for animated plots.

Here is a reproducible example inspired from your Readme:

library(ggsn); library(ggplot2); library(sf); library(gganimate)
#> Loading required package: ggplot2
#> Loading required package: grid
#> Linking to GEOS 3.5.1, GDAL 2.1.3, PROJ 4.9.2
data("domestic_violence")
(ggm1 <- ggplot(domestic_violence, aes(fill = Scaled)) +
    geom_sf() +
    scale_fill_continuous(low = "#fff7ec", high = "#7F0000") +
    ggsn::scalebar(domestic_violence, dist = 4, dist_unit = "km",
             transform = TRUE, model = "WGS84"))


gganimate::animate(
  ggm1 + transition_states(Value),
  nframes = 5
)

Created on 2019-04-17 by the reprex package (v0.2.1)

As you can see, the scale bar is not rendered properly in all of the images of the animations. Furthermore, it raises an error when using transition_time() that I suspect must be due to the same underlying cause.

oswaldosantos commented 5 years ago

Try with ggsn 0.5.1 and if the bug was fixed, close the issue please.

famuvie commented 5 years ago

Yes. It's fixed now. Thanks!

oswaldosantos commented 5 years ago

I had to add another argument to make scalebar work with gganimate. Use st.inherit = FALSE if scale bar has an unexpected behavior when used in animations.

famuvie commented 5 years ago

Noted, thanks.