By Hannah Bowers

For this project I used the Titanic Data Set from Kaggle.com. Truthfully there were not enough variables to do what I would consider a good analysis.

There are 15 columns in the Data Set and they are- PassengerId: A unique identifier assigned to each passenger.

- Survived: A binary variable indicating whether the passenger survived (1) or did not survive (0).

- Pclass (Passenger Class): The ticket class of the passenger, which can be 1st (1), 2nd (2), or 3rd (3) class.

- Name: The name of the passenger.

- Sex: The gender of the passenger (male or female).

- Age: The age of the passenger in years. It may contain missing values.

- SibSp: The number of siblings or spouses the passenger had aboard the Titanic.

- Parch: The number of parents or children the passenger had aboard the Titanic.

- Ticket: The ticket number.

- Fare: The amount of money the passenger paid for the ticket.

- Cabin: The cabin number where the passenger stayed. It may contain missing values.

- Embarked: The port at which the passenger boarded the Titanic (C for Cherbourg, Q for Queenstown, S for Southampton).

Male Passengers vs Female Passengers per class

I wanted to see which class had the most females overall and which was the closest to have an even number of males and females. Originally I thought it would be closer in third class but first class is closest. I knew that there were more men than women on the titanic so these comparisons were not surprising.

P1 <- ggplot(Titanic, aes(pclass)) +
  geom_bar(aes(fill = sex), position="dodge", stat = 'count')
P1

Spread of the ages of the passengers that survived vs the ages of those who didn’t

Next I was curious about the ages of those that survived and those that didn’t. In my head I thought that younger people might be more likely survive because of the expression “women and children first” in an emergency. But I had been surprised looking at the comparison that the distribution of the ages was pretty even.

P2 <- ggplot(Titanic, aes(x = survived, y = age ))+
  geom_boxplot()
P2
## Warning: Removed 263 rows containing non-finite outside the scale range
## (`stat_boxplot()`).

Comparing the Classes of Passengers that Boarded at each Port

Third I wanted to see where the most people in each class boarded. I found out that more first class passengers boarded in Charbourg and third class passengers boarded more in Queenstown and Southampton. Geographically that makes sense since even today Charbourg is a nicer area than Queenstown and Southampton.

TitanicC = Titanic[Titanic$embarked == "C",]
TitanicQ = Titanic[Titanic$embarked == "Q",]
TitanicS = Titanic[Titanic$embarked == "S",]
barC <- ggplot(TitanicC, aes(x = factor(1), fill = factor(pclass))) + geom_bar(width = 1)+ 
  coord_polar(theta = "y") + theme_void()
barQ <- ggplot(TitanicQ, aes(x = factor(1), fill = factor(pclass))) + geom_bar(width = 1)+ 
  coord_polar(theta = "y") + theme_void()
barS <- ggplot(TitanicS, aes(x = factor(1), fill = factor(pclass))) + geom_bar(width = 1)+ 
  coord_polar(theta = "y") + theme_void()

p3 <- ggarrange(barC,barQ,barS, 
                labels = c("Cherbourg","Queenstown","Southhampton"),
                ncol = 2, nrow = 2)
p3

Survival by Class and Gender

Next I wanted to see what the rates of survival were for each gender by class. Again the phrase “women and children first” stuck into my mind and women were much more likely to survive than men! Specifically the first class women had the highest rate of survival among any group. As for the men the first class men had the highest survival rate but it was still less than third class women.

Titanic3 <- Titanic
Titanic3$survived <- as.numeric(Titanic$survived)

Titanic4 <- Titanic3 %>%
  group_by(sex, pclass) %>%
  dplyr::summarize(Meansur = mean(survived, na.rm=TRUE)) %>%
  as.data.frame()
## `summarise()` has grouped output by 'sex'. You can override using the `.groups`
## argument.
p7 <-ggplot(Titanic4, aes(x = factor(pclass), y = factor(sex),))+
  geom_tile(aes(fill = Meansur),color = "black")+
  theme_minimal()+
  scale_fill_continuous(low = "white", high = "red", breaks = seq(0,1,by=0.2))
p7

Number of Siblings/Spouses vs Parents/Children

Lastly I wanted to compare how many people had siblings or spouses vs parents and children. While most passengers has either either neither or one its interesting the few outliers of people with 9 siblings/spouses or 8 parents/children. I didnt really think many people brought their families with them on the trip.

sibs = count(Titanic, sibsp)
pars = count(Titanic, parch)
data1 <- c('0','1','2','3','4','5','6','7','8','9')
data2 <- c(889,319,42,20,22,6,0,0,9,0)
data3 <- c(1000,170,113,8,6,6,2,0,0,2)

sibpar <- data.frame(data1,data2,data3)

p6 <- ggplot(sibpar, aes(x=data1, group = 2))+
  geom_line(aes(y=data2), color = "red")+
  geom_line(aes(y=data3), color = "blue")+
  geom_point(aes(y=data2), color = "red")+
  geom_point(aes(y=data3), color = "blue")+
  geom_text_repel(aes(y=data2, label = data2, color = "blue"))+
  geom_text_repel(aes(y=data3, label = data3, color = "red"))
p6