R/survival_mean_class.R

Defines functions survival_mean_class

Documented in survival_mean_class

# Analyse survival rate based on ticket class.
#' @title Relationship between ticket class and survival.
#' @description This function analyses the relationship between survival rate and ticket class of the passengers.
#' @param df The Titanic dataframe which gets imported after running the import_data functions.
#' @param sub_class: Subset dataframe containing the Class for passengers and their respective survival rate.
#' @param sboc : Variable which stores the the analysis of the mean ticket class
#' @param plot_sboc: Variable to store the graph behind the analysis
#' @param sboc_output : a variable which stores both the analysis and plot results in a list.
#' @return the analysis behind the relationship between the ticket class and also the graph based on the relationship.
#' @examples survival_mean_class()
#' @export
survival_mean_class <- function(){
        library(ggplot2)
        df <- MidDatAnalysis::titanic_data
        meanset <- subset(df,Survived == 1 ,Pclass)
        sboc<- paste("The mean seat class of the survivors was :", mean(meanset$Pclass),"And the class with the most survival rate was Class:", round(mean(meanset$Pclass)),", which means that people with lower class had more chances of survival")
        sub_class <-data.frame(df$Survived,df$Pclass)
        colnames(sub_class) <- c("Survived", "Class")
        sub_class$Survived[sub_class$Survived==1] <-'Survived'
        sub_class$Survived[sub_class$Survived==0] <-'Not Survived'
        plot_sboc <-ggplot(sub_class, aes(Class))+ geom_bar(aes(fill=Survived))+ggtitle("Ticket Class - Survival Rate Graph")
        sboc_output <- list(sboc,plot_sboc)
        return(sboc_output)
}
unimi-dse/a2b3bab6 documentation built on Feb. 22, 2020, 5:43 a.m.