Home > Software engineering >  gganimate::shadow_mark(): exlude all layers but 1st one
gganimate::shadow_mark(): exlude all layers but 1st one

Time:01-05

I want to use shadow_mark() to leave just the 1st set of raw data remaining on the plot to show the initial conditions. I do:

require(ggplot2)
require(gganimate)

table(airquality$Month)

ggplot(airquality, aes(Day, Temp))  
  geom_line(aes(color = Month), size = 1)  
  transition_time(Month)  
  shadow_mark(colour = 'black', size = 0.75, exclude_layer = 6:9)

Unfortunately, the exclude_layer option does not have any effect. Am I doing something wrong or this is bug? I suspect I might not have a correct understanding of "layer".

enter image description here

CodePudding user response:

The exclude_layers argument is used to exclude geom layers, i.e. in your case you have one geom_line and hence one layer.

I don't know whether gganimate offers an option to achieve your desired result but my reading of the docs is that at least for shadow_mark there isn't.

But a workaround would be to add your "reference" line using a second geom_line

library(ggplot2)
library(gganimate)

ggplot(airquality, aes(Day, Temp))  
  geom_line(data = ~subset(.x, Month == min(Month), -Month), size = 1)  
  geom_line(aes(color = Month), size = 1)  
  transition_time(Month)
#> Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
#> ℹ Please use `linewidth` instead.

  • Related