# install.packages("titanic")Chocolate Glazed Donut
# install.packages("ggplot2")# bar graph
library(titanic)
data <- titanic_train
head(data) PassengerId Survived Pclass
1 1 0 3
2 2 1 1
3 3 1 3
4 4 1 1
5 5 0 3
6 6 0 3
Name Sex Age SibSp Parch
1 Braund, Mr. Owen Harris male 22 1 0
2 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38 1 0
3 Heikkinen, Miss. Laina female 26 0 0
4 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35 1 0
5 Allen, Mr. William Henry male 35 0 0
6 Moran, Mr. James male NA 0 0
Ticket Fare Cabin Embarked
1 A/5 21171 7.2500 S
2 PC 17599 71.2833 C85 C
3 STON/O2. 3101282 7.9250 S
4 113803 53.1000 C123 S
5 373450 8.0500 S
6 330877 8.4583 Q
library(ggplot2)
ggplot(data, aes(x = Pclass, fill = factor(Survived))) +
geom_bar(position = "dodge") +
labs(
title = "# Survived in Passenger Class",
x = "Passenger Class",
y = "# survived"
)# Mosaic Plot
library(titanic)
data <- titanic_train
mosaicplot(
table(data$Survived, data$Pclass),
main = "# Survived in Passenger Class",
xlab = "Passenger Class",
ylab = "# survived",
color = TRUE
)# Box Plot
library(titanic)
data <- titanic_train
boxplot(Survived ~ Pclass, data = titanic_train,
main = "Survival By Each Passenger Class",
xlab = "Survived",
ylab = "Pclass",
col = c("red", "gray"))# Stem Plot - I'm not sure how to interpret this
library(titanic)
data <- titanic_train
stem(titanic_train$Survived)
The decimal point is 1 digit(s) to the left of the |
0 | 00000000000000000000000000000000000000000000000000000000000000000000+469
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | 00000000000000000000000000000000000000000000000000000000000000000000+262
# Histogram
library(titanic)
data <- titanic_train
hist(titanic_train$Age,
main = "Age Distribution in the Titanic Dataset",
xlab = "Age",
ylab = "Frequency")