## gender race diabetes BMI
## 1 Males White No Overweight
## 2 Males Black No Normal weight
## 3 Males Black No Normal weight
## 4 Females Black Yes Overweight
## 5 Males Hispanic No Overweight
## 6 Females White No Overweight
## race gender diabetes BMI Freq
## 1 Black Females No Normal weight 347
## 2 Hispanic Females No Normal weight 712
## 3 White Females No Normal weight 998
## 4 Black Males No Normal weight 429
## 5 Hispanic Males No Normal weight 706
## 6 White Males No Normal weight 873
##
## 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
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:tidyr':
##
## extract
library(ggalluvial)
##運用老師上教的指令帶入ggplot圖
p<- ggplot(dta_v3,
aes(axis1=race,
axis2=gender,
axis3=diabetes,
y=Freq)) +
scale_x_discrete(limits=c("race",
"gender",
"diabetes"),
expand=c(.1, .01)) +
labs(x='BMI',
y='SEQN') +
geom_alluvium(aes(fill=BMI)) +
geom_stratum() +
geom_text(stat="stratum",
infer.label=TRUE) +
scale_fill_manual(values=c('gray60','hotpink'))+
theme_minimal() +
ggtitle("Subjects stratified by diabetes in overall population")
p
