-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualisation-titanic.R
58 lines (44 loc) · 1.53 KB
/
visualisation-titanic.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
options(digits = 3)
library(tidyverse)
library(titanic)
library(gridExtra)
titanic <- titanic_train %>%
select(Survived, Pclass, Sex, Age, SibSp, Parch, Fare) %>%
mutate(Survived = factor(Survived),
Pclass = factor(Pclass),
Sex = factor(Sex))
titanic %>% filter(!is.na(Age)) %>%
ggplot(aes(Age, fill = Sex)) +
geom_density(aes(y = ..count..), alpha = 0.2)
titanic %>% filter(!is.na(Age)) %>%
ggplot(aes(Age, Sex)) +
geom_point()
params <- titanic %>%
filter(!is.na(Age)) %>%
summarize(mean = mean(Age), sd = sd(Age))
titanic %>% filter(!is.na(Age)) %>%
ggplot(aes(sample = Age)) +
geom_qq(dparams = params) +
geom_abline()
titanic %>% filter(!is.na(Survived)) %>%
ggplot(aes(Survived, fill = Sex)) +
geom_bar(position = position_dodge())
titanic %>% filter(!is.na(Age), !is.na(Survived)) %>%
ggplot() +
geom_density(aes(Age, y = ..count.., fill = Survived), alpha = 0.2)
titanic %>% filter(!is.na(Survived), !is.na(Fare), Fare > 0) %>%
ggplot(aes(Survived, Fare)) +
geom_boxplot() +
scale_y_continuous(trans = "log2") +
geom_jitter(alpha = 0.2)
b1 <- titanic %>% ggplot(aes(Pclass, fill = Survived))+
geom_bar()
b2 <- titanic %>% ggplot(aes(Pclass, fill = Survived))+
geom_bar(position = position_fill())
b3 <- titanic %>% ggplot(aes(Survived,fill = Pclass))+
geom_bar(position = position_fill())
grid.arrange(b1, b2, b3, ncol = 3)
titanic %>% filter(!is.na(Age)) %>%
ggplot()+
geom_density(aes(Age, y = ..count.., fill = Survived), alpha = 0.2) +
facet_grid(Sex ~ Pclass)