ggpp icon indicating copy to clipboard operation
ggpp copied to clipboard

geom_zebra_bands()

Open aphalo opened this issue 3 years ago • 4 comments

A geom to highlight boundaries, such as day and night or times with abnormal data, etc. It would be similar to geom_col() but not anchored on zero. It would use aesthetics ymin and ymax, with -Inf and Inf supported for edge to edge bands. geom_col() does not support -Inf mapped to y, and is based at zero. geom_area() seems to fail with POSIXct mapped to x. Ideally alpha should affect both fill and colour.

The example below was produced with two geom_col() layers.

  geom_col(aes(x = time,
               y = Inf,
               fill = day_or_night),
           alpha = 0.1) +
  geom_col(aes(x = time,
               y = -5,
               fill = day_or_night),
           alpha = 0.1) +
  scale_fill_manual(name = "",
                    values = c(day = "yellow", night = "grey50"),
                    aesthetics = c("colour", "fill")) +

Rplot

aphalo avatar Dec 01 '22 22:12 aphalo

Well, one can use geom_area() for this, easily if the time step in consistent. A statistics to compute the values for/night trnasitions could be useful, though.

aphalo avatar Dec 04 '22 22:12 aphalo

I think one could build this geom as a wrapper on geom_rect() allowing arbitrary widths for the alternating zebra bands. One would need some way of setting the two colours and the leftmost colour for alternations. Something like two variables one for x.dawn and x.dusk.

aphalo avatar Feb 20 '23 13:02 aphalo

A more general name for the variables such as switch.on and switch.off would be better than dawn and dusk, as the geom could be used for any cyclic or alternating states.

aphalo avatar May 13 '23 20:05 aphalo

Moved to next milestone. I need to still ponder on the best UI and how to implement it.

aphalo avatar Jul 08 '23 19:07 aphalo