oswaldosantos/ggsn

Compatibility with gganimate

famuvie opened this issue · 4 comments

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.

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

Yes. It's fixed now. Thanks!

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.

Noted, thanks.