corybrunson / ggalluvial

ggplot2 extension for alluvial plots
http://corybrunson.github.io/ggalluvial/
GNU General Public License v3.0
497 stars 34 forks source link

option for x scale geom parameters to account for differences between axes #47

Closed corybrunson closed 4 years ago

corybrunson commented 4 years ago

Description of the issue

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")

Created on 2020-01-03 by the reprex package (v0.3.0)

corybrunson commented 4 years ago

This is underway in the ribbons branch. Functionality may be complete but tests and examples are needed.

corybrunson commented 4 years ago

This was resolved in an earlier patch and was included in v0.12.0.