OCHA-DAP / gghdx

HDX Theme, Scales, and Other Conveniences for 'ggplot2'
GNU General Public License v3.0
5 stars 0 forks source link

issue with gganimate #12

Closed zackarno closed 1 year ago

zackarno commented 1 year ago

Check out the reprex below. I had issues with a similar error before with standard {ggplot2} when I didn't properly make the {sysfonts]/{showtext} calls:

sysfonts::font_add_google("Source Sans Pro")
showtext::showtext_auto()

Now that I know about the gghdx() function, i think the above are unnecessary, but am still getting these errors when trying to use with {gganimate]. When using the fill argument, the plot does not get generated. Without the fill argument a plot is generated, but still lots of warnings

library(tidyverse)
library(gghdx)
library(gganimate)
gghdx()

df <- data.frame(
  year = c(2010, 2010, 2010, 2013, 2013,2013, 2014,2014,2014),
  category = c("A", "B", "C", "A", "B", "C", "A", "B", "C"),
  pct_val = c(0.05, 0.12, 0.21, 0.37, 0.44, 0.53, 0.69, 0.76, 0.82)
)

df %>% 
  ggplot(aes(x=category,y=pct_val, fill=category)) +
  geom_bar(stat="identity")+
  coord_flip()+
  transition_time(year)
#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"

#> Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): no font could
#> be found for family "Source Sans Pro"
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : no
#> font could be found for family "Source Sans Pro"
#> Warning: Cannot get dimensions of plot table. Plot region might not be fixed
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : no
#> font could be found for family "Source Sans Pro"

#> this keeps repeating for a while

If i do it without the fill argument, the graph does still plot, but we get a similar warning


df %>% 
  ggplot(aes(x=category,y=pct_val)) +
  geom_bar(stat="identity")+
  coord_flip()+
  transition_time(year)
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : no
#> font could be found for family "Source Sans Pro"
#> Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : no
#> font could be found for family "Source Sans Pro"
#> Warning: Cannot get dimensions of plot table. Plot region might not be fixed

Created on 2023-05-29 with reprex v2.0.2

caldwellst commented 1 year ago

I have created a slightly narrower reprex and created an issue on the gganimate page. The plot is still generated, so I don't think is a problem at the moment. Either way, the issue lies somewhere with how showtext and gganimate work on the backend, so nothing clear that I can do.

However, this problem does not exist when I have Source Sans Pro installed directly on my machine. I will add that as a recommendation to the main page, and try and tackle the other issues of missing font warnings with something more informative.

zackarno commented 1 year ago

I have created a slightly narrower reprex and created an issue on the https://github.com/thomasp85/gganimate/issues/482.

:fire: i'll keep an eye on that!

The plot is still generated, so I don't think is a problem at the moment

For me the plot with the fill argument utilized is not generated, just the second one (without fill) is? same with you?