-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New position adjustment: position_connect()
#6231
base: main
Are you sure you want to change the base?
Conversation
Per discussion in the linked issue, here is an example of a KM curve next to ggsurvplot (who I trust have implemented this correctly for KM curves). devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
library(survival)
model <- survfit(Surv(time, status) ~ x, data = aml)
df <- broom::tidy(model)
ggplot(df, aes(time, estimate, ymin = conf.low, ymax = conf.high)) +
geom_step(aes(colour = strata)) +
geom_ribbon(
aes(fill = strata), alpha = 0.2,
position = "connect"
) ggsurvfit::ggsurvfit(model) +
ggsurvfit::add_confidence_interval() +
theme_gray()
#> Warning: Ignoring unknown labels:
#> • `linetype = "NULL"` Created on 2024-12-11 with reprex v2.1.1 I suspect ggsurvfit does some extra steps to ensure series start at 'time = 0' and 'probability = 1', but the CI ribbons look not too bad. |
I'm a bit on the fence with this, tbh. There is obvious utility in its generality, but Position adjustments shouldn't make up new data - it is only for moving existing data around. Now, you could argue that a straight line is an infinite set of points between two extremes so it is just moving those points around, but I think that would be stretching it a bit. Conceptually this feels like it belongs in a stat, but that would preclude it from being used together with other stats like in the examples above. However, I feel we did touch on the idea of having a |
That makes sense to me. Once we can chain stats, we can reshape this into a |
This PR aims to fix #6228.
It introduces a new position adjustment that can be used to connect points via steps or other shapes.
It is probably best introduced with some examples:
Created on 2024-12-11 with reprex v2.1.1