1. 타이타닉 선실 등급 별 생존 여부
#Class=1st, 2nd, 3rd, Crew / Survived=Yes, No > data("Titanic") > str(Titanic) table [1:4, 1:2, 1:2, 1:2] 0 0 35 0 0 0 17 0 118 154 ... - attr(*, "dimnames")=List of 4 ..$ Class : chr [1:4] "1st" "2nd" "3rd" "Crew" ..$ Sex : chr [1:2] "Male" "Female" ..$ Age : chr [1:2] "Child" "Adult" ..$ Survived: chr [1:2] "No" "Yes" > apply(Titanic,c(1,4),sum) Survived Class No Yes 1st 122 203 2nd 167 118 3rd 528 178 Crew 673 212 > addmargins(apply(Titanic,c(1,4),sum)) Survived Class No Yes Sum 1st 122 203 325 2nd 167 118 285 3rd 528 178 706 Crew 673 212 885 Sum 1490 711 2201 > par(mfrow=c(1,2)) > mosaicplot(~Class+Survived,data=Titanic) > mosaicplot(~Class+Survived,data=Titanic,color=c('grey','red'))
2. 타이타닉 성별/연령 별 생존 여부
> mosaicplot(~Sex+Survived,data=Titanic,color=c('grey','red')) > mosaicplot(~Age+Survived,data=Titanic,color=c('grey','red'))
3. 타이타닉 성인 남성 / 성인 여성 생존 여부
> mosaicplot(~Class+Survived,data=as.table(Titanic[,'Male','Adult',]),color=c('grey','red'), main="Male+Adult") > mosaicplot(~Class+Survived,data=as.table(Titanic[,'Female','Adult',]),color=c('grey','red'), main="Female+Adult")