My Shiny App: Titanic Survival Rate

Abdullah M. Mustafa
Jan, 6th 2020

Overview:

  • This presentation explains the developed shiny application for the Titanic Dataset.
  • We estiamte the [survival/death] rates for different variables in the data [Class/Sex/Age].
  • The application (my_shiny_app) is available at this link

Server Code

The following code for the server is avaliable at Github

x = switch(input$group, class = 'Class',sex = 'Sex',age = 'Age','Class')
Survival <- switch(input$rate, survival = TRUE, death = FALSE, TRUE)
data <- Titanic_data %>% group_by_at(vars(x,'Survived')) %>% summarise(Total = sum(Freq))
data_split <- data.frame(split(data$Total, data[x]))
if (Survival)
    {Mortality_rate <- data.frame(rate = sapply(data_split, function(x){x[2]/sum(x)}))}
else
    {Mortality_rate <- data.frame(rate = sapply(data_split, function(x){x[1]/sum(x)}))}
      Mortality_rate$var <- rownames(Mortality_rate)
      ggplot(aes(var,rate),data=Mortality_rate)+geom_bar(stat = "identity")+
          labs(x=x,y='Percentage',title="Titanic Survival")

Example Plots

This plot is for the Class variable showing the survival rate. plot of chunk fig.width

Conclusion

Overall, we can see for these data that survivor rate increases with: 1 . First class has higher survival rate. 2 . Females have higher survival rates. 3 . Children have higher survival rates.