-
Notifications
You must be signed in to change notification settings - Fork 1
/
SW03_EDA.R
160 lines (126 loc) · 6.01 KB
/
SW03_EDA.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
library(ggplot2)
## Read data source and modify column names
studPerf <- read_csv("./StudentsPerformance.csv",
col_types = cols(gender = col_factor(levels = c("female", "male")),
'race/ethnicity' = col_factor(levels = c("group A", "group B", "group C", "group D", "group E")),
'parental level of education' = col_factor(levels = c("bachelor's degree", "some college", "master's degree", "associate's degree", "high school", "some high school")),
lunch = col_factor(levels = c("free/reduced", "standard")),
'test preparation course' = col_factor(levels = c("none", "completed")),
'math score' = col_integer(),
'reading score' = col_integer(),
'writing score' = col_integer()))
studPerf <- as.data.frame(studPerf)
namesOfColumns <- c("Gender","Race","Parent_Education","Lunch","Test_Prep","Math_Score","Reading_Score","Writing_Score")
colnames(studPerf) <- namesOfColumns
studPerf <- as_tibble(studPerf)
studPerf <- mutate(studPerf, totalScore = studPerf$Math_Score+studPerf$Reading_Score+studPerf$Writing_Score)
View(studPerf)
mathPlot <- ggplot(data = studPerf, mapping = aes(x = Math_Score))
mathPlot + geom_histogram()
readPlot <- ggplot(data = studPerf, mapping = aes(x = Reading_Score))
readPlot + geom_histogram()
writePlot <- ggplot(data = studPerf, mapping = aes(x = Writing_Score))
writePlot + geom_histogram()
plot <- ggplot(data = studPerf, mapping = aes(x = Gender))
plot + geom_violin(mapping = aes(y = Math_Score))
plot <- ggplot(data = studPerf, mapping = aes(x =Lunch))
plot + geom_violin(mapping = aes(y = Math_Score))
plot <- ggplot(data = studPerf, mapping = aes(x = Race))
plot + geom_violin(mapping = aes(y = Math_Score))
plot <- ggplot(data = studPerf, mapping = aes(x = Parent_Education))
plot + geom_violin(mapping = aes(y = Math_Score))
ggplot(studPerf, aes(x=Parent_Education, y=Math_Score, color=Gender)) +
geom_point() +
scale_color_manual(values=c("green", "red")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="math score")
ggplot(studPerf, aes(x=Race, y=Math_Score, color=Gender)) +
geom_point() +
scale_color_manual(values=c("green", "red")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="reading score")
ggplot(studPerf, aes(Math_Score)) +
geom_histogram(binwidth=5, color="gray", aes(fill=Gender)) +
xlab("Math Scores") +
ggtitle("Math Scores by Gender")
ggplot(studPerf, aes(Reading_Score)) +
geom_histogram(binwidth=5, color="gray", aes(fill=Gender)) +
xlab("Reading Scores") +
ggtitle("Reading Scores by Gender")
ggplot(studPerf, aes(Writing_Score)) +
geom_histogram(binwidth=5, color="gray", aes(fill=Gender)) +
xlab("Writing Scores") +
ggtitle("Writing Scores by Gender")
ggplot(studPerf, aes(x=Gender, y=Math_Score, color=Lunch)) +
geom_bin2d() +
facet_wrap(vars(Parent_Education)) +
scale_color_manual(values=c("green", "red")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="math score")
ggplot(studPerf, aes(x=Gender, y=Writing_Score, color=Lunch)) +
geom_bin2d() +
facet_wrap(vars(Parent_Education)) +
scale_color_manual(values=c("green", "red")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="writing score")
ggplot(studPerf, aes(x=Gender, y=Reading_Score, color=Lunch)) +
geom_bin2d() +
facet_wrap(vars(Parent_Education)) +
scale_color_manual(values=c("green", "red")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="reading score")
ggplot(studPerf, aes(x=Math_Score, y=Reading_Score)) +
geom_density2d() +
facet_grid(vars(Parent_Education)) +
scale_color_manual(values=c("red", "green")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="Reading score")
ggplot(studPerf, aes(x=Math_Score, y=Reading_Score,color=Gender)) +
geom_density2d() +
facet_grid(vars(Parent_Education)) +
scale_color_manual(values=c("red", "green")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="Reading score")
ggplot(studPerf, aes(x=Math_Score, y=Reading_Score,color=Test_Prep)) +
geom_density2d() +
facet_grid(vars(Parent_Education)) +
scale_color_manual(values=c("red", "green")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="Reading score")
ggplot(studPerf, aes(x=Math_Score, y=Reading_Score,color=Gender)) +
geom_point() +
facet_grid(vars(Parent_Education)) +
scale_color_manual(values=c("red", "green")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="Reading score")
ggplot(studPerf, aes(x=Math_Score, y=Reading_Score,color=Test_Prep)) +
geom_point() +
facet_grid(vars(Parent_Education)) +
scale_color_manual(values=c("blue", "yellow")) +
scale_y_continuous(breaks=c(0,25,50,75,100),
labels=c(0,25,50,75,100),
name="Reading score")
ggplot(studPerf, aes(Gender, Writing_Score, color = Test_Prep)) +
geom_boxplot() +
ggtitle("Writing scores by Gender Boxplot") +
xlab("Gender") +
ylab("Writing Scores")
ggplot(studPerf, aes(Gender, Reading_Score, color = Test_Prep)) +
geom_boxplot() +
ggtitle("REading scores by Gender Boxplot") +
xlab("Gender") +
ylab("Reading Scores")
ggplot(studPerf, aes(Gender, Math_Score, color = Test_Prep)) +
geom_boxplot() +
ggtitle("Math scores by Gender Boxplot") +
xlab("Gender") +
ylab("Math Scores")