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).
P1 <- ggplot(Titanic, aes(pclass)) +
geom_bar(aes(fill = sex), position="dodge", stat = 'count')
P1
P2 <- ggplot(Titanic, aes(x = survived, y = age ))+
geom_boxplot()
P2
## Warning: Removed 263 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
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
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
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