Change scale in gganimate ?

I have some time series data recorded in hours. In one of the sets (hour 5 of 10), the values are much higher than the rest of the sets. This affects the color legend for all frames of my gganimate plot. How can I make the color legend return for the other sets with 'normal' values?

Minimal reprex using the gapminder dataset:

Original:

library(gganimate)
library(gapminder)

ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, colour = lifeExp)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  facet_wrap(~continent) +
  # Here comes the gganimate specific bits
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

What happens if one life expecancy in 1 year is channged to 1000?
All frames are affected

gapminder2 <- gapminder
gapminder2[1,c("lifeExp")] <- 1000

ggplot(gapminder2, aes(gdpPercap, lifeExp, size = pop, colour = lifeExp)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  facet_wrap(~continent) +
  # Here comes the gganimate specific bits
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.