plot_sexCHD = heart%>%
group_by(TenYearCHD, male)%>%
summarise(cnt = n())%>%
mutate(pcnt = cnt/sum(cnt))%>%
ggplot(aes(x = as.factor(male), y = pcnt, fill = TenYearCHD))+
geom_bar(col = "white", position = "dodge", stat = "identity")+
labs(x = "Sex", y = "Percentage", title = 'Male Female Percentage of CHD')+
scale_fill_brewer(palette = "Blues")
str(heart)
'data.frame': 4238 obs. of 16 variables:
male : int 1 0 1 0 0 0 0 0 1 1 ...
age : int 39 46 48 61 46 43 63 45 52 43 ...
education : int 4 2 1 3 3 2 1 2 1 1 ...
currentSmoker : int 0 0 1 1 1 0 0 1 0 1 ...
cigsPerDay : int 0 0 20 30 23 0 0 20 0 30 ...
BPMeds : int 0 0 0 0 0 0 0 0 0 0 ...
prevalentStroke: int 0 0 0 0 0 0 0 0 0 0 ...
prevalentHyp : int 0 0 0 1 0 1 0 0 1 1 ...
diabetes : int 0 0 0 0 0 0 0 0 0 0 ...
totChol : int 195 250 245 225 285 228 205 313 260 225 ...
sysBP : num 106 121 128 150 130 ...
diaBP : num 70 81 80 95 84 110 71 71 89 107 ...
BMI : num 27 28.7 25.3 28.6 23.1 ...
heartRate : int 80 95 75 65 85 77 60 79 76 93 ...
glucose : int 77 76 70 103 85 99 85 78 79 88 ...
TenYearCHD : int 0 0 0 1 0 0 1 0 0 0 ...