ggplot2: Shade area under a step line

I am trying to build a stacked step line graphic, adding cumulative area under a set of 4 (cumulative) survival curves. But geom_area() and geom_ribbon() seem to want to plot under regular, not step lines. Here I have plotted the ribbon and the step line in the reverse order so that one can see in red what the boundary should be, and in the blue the fill area supplied by geom_area).

pt1 %>% ggplot() + geom_area(aes(time, state4), fill = 'blue', alpha = 0.8) +
geom_step(aes(time, state4), col = 'red')

Is there a way to convince the geom_area (or geom_fill) to use the step_line borders instead of the usual line borders? Thanks for any help with this issue.
Larry Hunsicker

Please provide a reproducible example for us to work with.

I found an answer: [https://stackoverflow.com/questions/43587411/area-between-step-wise-functions-in-r].
Thanks to Brian from StackOverflow.

1 Like

This topic was automatically closed 7 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.