1

I'm very new to making graphs in R and I'm having a hard time producing a simple alluvial plot.

My data is basically something like this (I've already aggregated it):

data<-tibble(working_2019=c("Yes", "No", "Yes", "No"),
            working_2022=c("Yes", "No", "No", "Yes"),
            obs=c(20,30,40,10))

This is what I have so far, and when I try following other people's code it never works (mostly because all other examples use the option "fill" to get categories within a stratum, and I don't think it's needed here).

ggplot(data, aes(y=obs, axis1=working_2019, axis2=working_2022))+
  geom_alluvium( width=0,knot.pos=0, reverse=F)+
  geom_stratum(width = 1/16)

I'd like to get something like this, with 2019 as the left axis and 2022 as the right one, and then label each axis with "Working" and "Not Working" Example alluvial plot

Thanks in advance!

Quinten
  • 35,235
  • 5
  • 20
  • 53
mau
  • 11
  • 2

1 Answers1

0

To get the labels on x-axis you could use scale_x_discrete with limits like this:

library(ggalluvial)
#> Loading required package: ggplot2
ggplot(data, aes(y=obs, axis1=working_2019, axis2=working_2022))+
  geom_alluvium( width=0,knot.pos=0, reverse=F)+
  geom_stratum(width = 1/16) +
  scale_x_discrete(limits = c("2019", "2022"), expand = c(.05, .05)) 
#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.

#> Warning in to_lodes_form(data = data, axes = axis_ind, discern =
#> params$discern): Some strata appear at multiple axes.

Created on 2022-08-31 with reprex v2.0.2

Quinten
  • 35,235
  • 5
  • 20
  • 53