Dataset, Titanic, provides information on the fate of passengers on the fatal maiden voyage of the ocean liner ‘Titanic’, summarized according to economic status (class), sex, age and survival. ## Summary
f<-data.frame(Titanic)
summary(f)
## Class Sex Age Survived Freq
## 1st :8 Male :16 Child:16 No :16 Min. : 0.00
## 2nd :8 Female:16 Adult:16 Yes:16 1st Qu.: 0.75
## 3rd :8 Median : 13.50
## Crew:8 Mean : 68.78
## 3rd Qu.: 77.00
## Max. :670.00
1.The dataset has 32 ( I used inline syntax here to compute total observations) observations with 5 variables.
2.The dataset has the same number of observations from different subsets.
I make barplots for survived adults and children from different classes by comparing the male and female.
require("dplyr")
f<-data.frame(Titanic)
survivedAdult<-filter(f, Survived == "Yes" & Age =="Adult" )
library(ggplot2)
g<-ggplot(survivedAdult, aes(factor(survivedAdult$Class), survivedAdult$Freq, fill = Sex)) + geom_bar(stat="identity", position = "dodge") + scale_fill_brewer(palette = "Set1")
print(g+ggtitle("Survived Adults from Different Class")+labs(y="Frequency", x="class")+ theme(plot.title = element_text(hjust = 0.5)))
survivedChild<-filter(f, Survived == "Yes" & Age =="Child" )
library(ggplot2)
g<-ggplot(survivedChild, aes(factor(survivedChild$Class), survivedChild$Freq, fill = Sex)) + geom_bar(stat="identity", position = "dodge") + scale_fill_brewer(palette = "Set1")
print(g+ggtitle("Survived Children from Different Class")+labs(y="Frequency", x="class") + theme(plot.title = element_text(hjust = 0.5)))