I am using generic Diabetes data,
datGluBMIAge <- dat[, .(freq = sum(freq)), by=list(Glucose_cat, BMI_cat, Age_cat, Outcome_cat)]
datGluBMIAge<- datGluBMIAge[!(is.na(datGluBMIAge$Age_cat))]
datGluBMIAge<- datGluBMIAge[!(is.na(datGluBMIAge$Glucose_cat))]
datGluBMIAge<- datGluBMIAge[!(is.na(datGluBMIAge$BMI_cat))]
setnames(datGluBMIAge, old = c('Glucose_cat', 'Age_cat','Outcome_cat', 'BMI_cat'), new = c('Glucose', 'Age','Diabetes','BMI'))
ggplot(datGluBMIAge,aes(axis1= Diabetes, axis2=Glucose, axis3 = BMI, axis4 = Age, y = freq)) +
geom_alluvium(aes(fill=Diabetes),aes.bind=TRUE, reverse = FALSE, alpha=0.9) +
scale_fill_manual(labels = c("Negative", "Positive"), values = c("#0066BA", "#FF9400")) +
scale_x_discrete(limits = c("Diabetes", "Glucose","BMI", "Age"), expand = c(0, 0)) +
scale_y_continuous(labels = NULL, expand = c(0,0))+
theme(axis.text.x=element_text(margin = margin(t = 0, unit='pt')),
axis.title.x = element_text(vjust = 0),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
axis.line = element_blank(),
axis.ticks = element_blank(),
legend.position = "none")+
geom_stratum(alpha=1, reverse = FALSE) +
geom_text(stat="stratum", label.strata= TRUE, reverse = FALSE) +
ylab(NULL)+xlab(NULL) +
geom_vline(xintercept = 0)
Above code produces this plot:
I have two question based on the above plot
there are various links going from
Glucose="Normal"
toBMI='30-35'
, how do i arrange them such a way that i see only one link going fromGlucose="Normal"
toBMI='30-35'
and all the othersHow can I change the color scheme between axis?for example if I want different colors between Glucose and BMI,and even different color between BMI and Age? How can I do it using the ggalluvial library?
any leads would be appreciated. Thank you for your time. Regards,Trupti