When a continuous variable is passed to x, the stats pass correct locations to the geoms. However, the geom parameters width and knot.pos take only fixed values and cannot take the differences between axes into account. This limits their flexibility in such plots, as illustrated below. It should be possible to specify that stratum widths and spline knot positions be proportional to between-axis differences, hence take different values on the two sides of each axis.
Reproducible example (preferably using reprex::reprex())
library(ggalluvial)
#> Loading required package: ggplot2
data(vaccinations)
# add survey dates to vaccination data
survey_dates <- data.frame(
survey = levels(vaccinations$survey),
start = as.Date(c("2010-09-22", "2015-06-04", "2016-09-27")),
end = as.Date(c("2010-10-25", "2015-10-05", "2016-10-25"))
)
vaccination_dates <- merge(vaccinations, survey_dates, by = "survey")
# plot with linear flows
ggplot(vaccination_dates,
aes(x = end, y = freq, stratum = response, alluvium = subject,
fill = response)) +
stat_alluvium(geom = "flow", lode.guidance = "forward",
width = 30, knot.pos = 0) +
stat_stratum(width = 30) +
labs(x = "Survey date", y = "Number of respondents")
# plot with x-splined flows
ggplot(vaccination_dates,
aes(x = end, y = freq, stratum = response, alluvium = subject,
fill = response)) +
stat_alluvium(geom = "flow", lode.guidance = "forward",
width = 90, knot.pos = 360) +
stat_stratum(width = 90) +
labs(x = "Survey date", y = "Number of respondents")
Description of the issue
When a continuous variable is passed to
x
, the stats pass correct locations to the geoms. However, the geom parameterswidth
andknot.pos
take only fixed values and cannot take the differences between axes into account. This limits their flexibility in such plots, as illustrated below. It should be possible to specify that stratum widths and spline knot positions be proportional to between-axis differences, hence take different values on the two sides of each axis.Reproducible example (preferably using
reprex::reprex()
)Created on 2020-01-03 by the reprex package (v0.3.0)