-
Notifications
You must be signed in to change notification settings - Fork 1
/
rproj.R
61 lines (47 loc) · 1.54 KB
/
rproj.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Load Titanic data for analysis. Open in spreadsheet view.
#titanic <- read.csv("titanic.csv", stringsAsFactors = FALSE)
#View(titanic)
library(ggplot2)
# Set up factors.
titanic$Pclass <- as.factor(titanic$Pclass)
titanic$Survived <- as.factor(titanic$Survived)
titanic$Sex <- as.factor(titanic$Sex)
titanic$Embarked <- as.factor(titanic$Embarked)
#
# Survival by class
#
ggplot(titanic, aes(x = Pclass, fill = Survived)) +
theme_bw() +
geom_bar() +
scale_fill_discrete(name = "Status",labels = c("Deceased", "Survived"))+
labs(y = "Passenger Count",
title = "Titanic Survival Rates by Class")
#Survival Rates by Embarked point
ggplot(titanic, aes(x = Embarked, fill = Survived)) +
theme_bw() +
geom_bar() +
coord_polar("y") +
scale_fill_discrete(name = "Status",labels = c("Deceased", "Survived"))+
labs(y = "Passenger Count",
title = "Titanic Survival Rates by Embarked point")
#
#Survival Rates by Class and Sex
#
ggplot(titanic, aes(x = Sex, fill = Survived)) +
theme_bw() +
facet_wrap(~ Pclass) +
geom_bar() +
scale_fill_discrete(name = "Status",labels = c("Deceased", "Survived"))+
labs(y = "Passenger Count",
title = "Titanic Survival Rates by Class and Sex")
#
# Survival Rates by Age, Class and Sex
#
ggplot(titanic, aes(x = Age, fill = Survived)) +
theme_bw() +
facet_wrap(Sex ~ Pclass) +
geom_density(alpha = 0.5) +
scale_fill_discrete(name = "Status",labels = c("Deceased", "Survived"))+
labs(y = "Age",
x = "Survived",
title = "Titanic Survival Rates by Age, Class and Sex")