Design an alluvial diagram to show changes in employment status over 3 years.
step1-load the required libraries
library(ggalluvial)
Loading required package: ggplot2
library(ggplot2)library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
library(readr)
step2-create a dataframe
data_2018 <-data.frame(Employment_Status =c("Employed", "Unemployed", "Not in Labour Force"),Count =c(60000, 15000, 25000))data_2019 <-data.frame(Employment_Status =c("Employed", "Unemployed", "Not in Labour Force"),Count =c(58000, 17000, 25000))data_2020 <-data.frame(Employment_Status =c("Employed", "Unemployed", "Not in Labour Force"),Count =c(55000, 20000, 25000))
step3-create a transition estimates
transition_data <-data.frame( Year_2018 =c("Employed", "Employed", "Unemployed", "Not in Labour Force", "Not in Labour Force"), Year_2019 =c("Employed", "Unemployed", "Unemployed", "Not in Labour Force", "Employed"), Year_2020 =c("Employed", "Unemployed", "Employed", "Not in Labour Force", "Unemployed"), Freq =c(45000, 15000, 10000, 20000, 5000) )
step4-plot alluvial diagram
ggplot(transition_data,aes(axis1 = Year_2018, axis2 = Year_2019, axis3 = Year_2020, y = Freq)) +scale_x_discrete(limits =c("2018", "2019", "2020"), expand =c(.1, .1)) +xlab("Year") +geom_alluvium(aes(fill = Year_2018), width =1/12) +geom_stratum(width =1/12, fill ="gray90", color ="black") +geom_text(stat ="stratum", aes(label =after_stat(stratum))) +theme_minimal() +ggtitle("Employment Status Transitions in India (2018–2020)") +theme(plot.title =element_text(face ="bold", hjust =0.5))
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.
Warning in to_lodes_form(data = data, axes = axis_ind, discern =
params$discern): Some strata appear at multiple axes.