-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.R
374 lines (297 loc) · 12.7 KB
/
main.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# REQUIRED LIBRARIES
library(ggplot2)
library(reshape2)
library(plyr)
library(dplyr)
library(gridExtra)
library(wesanderson)
library(pander)
library(plotly)
# READ DATASETS
infoCharacters <- read.csv("dataset_shdb/heroesInformation.csv", na.strings = c("-", "-99"))
infoPowers <- read.csv("dataset_shdb/superHeroPowers.csv")
infoStats <- read.csv("dataset_shdb/charactersStats.csv", na.strings = "")
# SUBSET FOR MARVEL AND DC
colnames(infoCharacters)[colnames(infoCharacters) == "name"] <- "Name"
marvelDcInfo <- infoCharacters[(infoCharacters$Publisher == "Marvel Comics" | infoCharacters$Publisher == "DC Comics"), ]
# REMOVE NAME DUPLICATES AND SELECT COLUMNS
marvelDcInfo <- marvelDcInfo[!duplicated(marvelDcInfo$Name), ]
marvelDcInfo <- marvelDcInfo %>%
select(Name, Gender, Race, Publisher)
# JOIN DATASETS
marvelDcStatsInfo <- join(marvelDcInfo, infoStats, by = "Name", type = "inner")
colnames(infoPowers)[colnames(infoPowers) == "hero_names"] <- "Name"
fullMarvelDc <- join(marvelDcStatsInfo, infoPowers, by = "Name", type = "inner")
# TRANSFORM INTO A SINGLE COLUMN SUPER POWER
marvelDc <- melt(fullMarvelDc, id = c("Name", "Gender", "Race", "Publisher", "Alignment", "Intelligence",
"Strength", "Speed", "Durability", "Power", "Combat", "Total"))
colnames(marvelDc)[colnames(marvelDc) == "variable"] <- "SuperPower"
marvelDc <- marvelDc %>%
filter(value == "True") %>%
select(-value)
# CONVERT CATEGORICAL COLUMNS TO FACTORS
marvelDc$Name <- as.factor(marvelDc$Name)
marvelDc$Gender <- as.factor(marvelDc$Gender)
marvelDc$Race <- as.factor(marvelDc$Race)
marvelDc$Publisher <- as.factor(marvelDc$Publisher)
marvelDc$Alignment <- as.factor(marvelDc$Alignment)
marvelDc$SuperPower <- as.factor(marvelDc$SuperPower)
# CUSTOM PALETTES
dcMarvelPalette <- c("#0476F2", "#EC1E24")
goodBadPalette <- c("#E58700", "#0EBF7D", "#C99902")
# DATA OBSERVATIONS IN EACH PUBLISHER
ggplot(marvelDc, aes(x = Publisher, fill = Publisher)) +
geom_bar(stat = "count", aes(fill = Publisher)) +
labs(x = "Publisher", y = "No. of Characters", title = "DC and Marvel Characters", subtitle = "No. of Characters each publisher") +
geom_label(stat = "count", aes(label = ..count..)) +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# MALES AND FEMALES IN DC AND MARVEL
marvelDcGender <- marvelDc %>%
filter(!is.na(Gender)) %>%
group_by(Gender) %>%
dplyr::count(Publisher) %>%
select(Gender, Publisher, Count = n)
ggplot(marvelDcGender, aes(x = Gender, y = Count)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Gender", y = "No. of Characters", title = "DC and Marvel Characters", subtitle = "Gender comparison") +
geom_label(stat = "identity", aes(label = Count)) +
facet_wrap(~Publisher) +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# RACE DIFFERENCE BETWEEN MARVEL AND DC
DCRace <- marvelDc %>%
filter(!is.na(Race)) %>%
filter(Publisher == "DC Comics") %>%
group_by(Race) %>%
dplyr::count(Race) %>%
select(Race, Count = n) %>%
arrange(-Count)
DCRace <- ggplot(DCRace[1:15, ], aes(x = reorder(Race, Count), y = Count)) +
geom_bar(stat = "identity", aes(fill = Race)) +
labs(x = "Race", y = "No. of Characters", title = "DC Character Races", subtitle= "Top 15 races") +
geom_label(stat = "identity", aes(label = Count)) +
coord_flip() +
guides(fill = FALSE, alpha = FALSE) +
theme_bw()
marvelRace <- marvelDc %>%
filter(!is.na(Race)) %>%
filter(Publisher == "Marvel Comics") %>%
group_by(Race) %>%
dplyr::count(Race) %>%
select(Race, Count = n) %>%
arrange(-Count)
marvelRace <- ggplot(marvelRace[1:15, ], aes(x = reorder(Race, Count), y = Count)) +
geom_bar(stat = "identity", aes(fill = Race)) +
geom_label(stat = "identity", aes(label = Count)) +
labs(x = "Race", y = "No. of Characters", title = "Marvel Character Races", subtitle= "Top 15 races") +
coord_flip() +
guides(fill = FALSE, alpha = FALSE) +
theme_bw()
grid.arrange(DCRace, marvelRace, ncol = 2)
# HEROES AND VILLIANS IN MARVEL AND DC
marvelDcAlignment <- marvelDc %>%
filter(!is.na(Alignment)) %>%
group_by(Alignment) %>%
dplyr::count(Publisher) %>%
select(Alignment, Publisher, Count = n)
ggplot(marvelDcAlignment, aes(x = Alignment, y = Count)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Alignment", y = "No. of Characters", title = "DC and Marvel Alignment", subtitle= "Heroes, Villains and Neutral comparison") +
guides(fill = FALSE) +
geom_label(stat = "identity", aes(label = Count)) +
facet_wrap(~Publisher) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# BOX PLOT COMPARISON SKILLS MARVEL AND DC
### INTELLIGENCE
boxIntel <- ggplot(marvelDc, aes(x = Publisher, y = Intelligence, fill = Publisher)) +
geom_boxplot() +
labs(x = "", title = "DC and Marvel Characters", subtitle = "Comparison of Intelligence") +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
### STRENGTH
boxStrength <- ggplot(marvelDc, aes(x = Publisher, y = Strength, fill = Publisher)) +
geom_boxplot() +
labs(x = "", title = "DC and Marvel Characters", subtitle = "Comparison of Strength") +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
### SPEED
boxSpeed <- ggplot(marvelDc, aes(x = Publisher, y = Speed, fill = Publisher)) +
geom_boxplot() +
labs(x = "", title = "DC and Marvel Characters", subtitle = "Comparison of Speed") +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
### DURABILITY
boxDurability <- ggplot(marvelDc, aes(x = Publisher, y = Durability, fill = Publisher)) +
geom_boxplot() +
labs(x = "", title = "DC and Marvel Characters", subtitle = "Comparison of Durability") +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
### POWER
boxPower <- ggplot(marvelDc, aes(x = Publisher, y = Power, fill = Publisher)) +
geom_boxplot() +
labs(x = "", title = "DC and Marvel Characters", subtitle = "Comparison of Power") +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
### COMBAT
boxCombat <- ggplot(marvelDc, aes(x = Publisher, y = Combat, fill = Publisher)) +
geom_boxplot() +
labs(x = "", title = "DC and Marvel Characters", subtitle = "Comparison of Combat") +
guides(fill = FALSE) +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
grid.arrange(boxIntel, boxStrength, boxSpeed, boxDurability, boxPower, boxCombat, ncol = 2)
# TOP CHARACTERS HIGHEST INTELLIGENCE MARVEL AND DC
marvelDcIntel <- marvelDc %>%
group_by(Name, Publisher) %>%
distinct(Intelligence) %>%
select(Name, Intelligence) %>%
arrange(-Intelligence)
ggplot(marvelDcIntel[1:30, ], aes(x = reorder(Name, Intelligence), y = Intelligence)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
ylim(0, 120) +
labs(x = "Character", y = "Intelligence", title = "Top 30 Marvel and DC Characters", subtitle = "With Highest Intelligence") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# TOP CHARACTERS HIGHEST STRENGTH MARVEL AND DC
marvelDcStrength <- marvelDc %>%
group_by(Name, Publisher) %>%
distinct(Strength) %>%
select(Name, Strength) %>%
arrange(-Strength)
ggplot(marvelDcStrength[1:30, ], aes(x = reorder(Name, Strength), y = Strength)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Character", y = "Strength", title = "Top 30 Marvel and DC Characters", subtitle = "With Highest Strength") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# TOP CHARACTERS HIGHEST SPEED MARVEL AND DC
marvelDcSpeed <- marvelDc %>%
group_by(Name, Publisher) %>%
distinct(Speed) %>%
select(Name, Speed) %>%
arrange(-Speed)
ggplot(marvelDcSpeed[1:30, ], aes(x = reorder(Name, Speed), y = Speed)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Character", y = "Speed", title = "Top 30 Marvel and DC Characters", subtitle = "With Highest Speed") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# TOP CHARACTERS HIGHEST DURABILITY MARVEL AND DC
marvelDcDur <- marvelDc %>%
group_by(Name, Publisher) %>%
distinct(Durability) %>%
select(Name, Durability) %>%
arrange(-Durability)
ggplot(marvelDcDur[1:30, ], aes(x = reorder(Name, Durability), y = Durability)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
ylim(0, 120) +
labs(x = "Character", y = "Durability", title = "Top 30 Marvel and DC Characters", subtitle = "With Highest Durability") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# TOP CHARACTERS HIGHEST POWER MARVEL AND DC
marvelDcPow <- marvelDc %>%
group_by(Name, Publisher) %>%
distinct(Power) %>%
select(Name, Power) %>%
arrange(-Power)
ggplot(marvelDcPow[1:30, ], aes(x = reorder(Name, Power), y = Power)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Character", y = "Power", title = "Top 30 Marvel and DC Characters", subtitle = "With Highest Power") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# TOP CHARACTERS HIGHEST COMBAT SKILLS MARVEL AND DC
marvelDcCombat <- marvelDc %>%
group_by(Name, Publisher) %>%
distinct(Combat) %>%
select(Name, Combat) %>%
arrange(-Combat)
ggplot(marvelDcCombat[1:30, ], aes(x = reorder(Name, Combat), y = Combat)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Character", y = "Combat", title = "Top 30 Marvel and DC Characters", subtitle = "With Highest Combat Skills") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# BOXPLOT OVERALL COMPARISION MARVEL AND DC
ggplot(marvelDc, aes(x = Publisher, y = Total, fill = Publisher)) +
geom_boxplot() +
labs(x = "Publisher", title = "DC and Marvel Characters", subtitle = "Most Powerful Characters Comparison (Sum of abilities)") +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)
# TOP POWERFUL CHARACTERS MARVEL AND DC
dcTotal <- marvelDc %>%
filter(Publisher == "DC Comics") %>%
group_by(Name, Alignment) %>%
distinct(Total) %>%
select(Name, Total) %>%
arrange(-Total)
dcTotal <- ggplot(dcTotal[1:20, ], aes(x = reorder(Name, Total), y = Total)) +
geom_bar(stat = "identity", aes(fill = Alignment)) +
labs(x = "Character", y = "Total", title = "Top 20 DC Characters", subtitle = "Most Powerful Heroes or Villains") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=goodBadPalette, labels = c("villain", "hero", "neutral"))
marvelTotal <- marvelDc %>%
filter(Publisher == "Marvel Comics") %>%
group_by(Name, Alignment) %>%
distinct(Total) %>%
select(Name, Total) %>%
arrange(-Total)
marvelTotal <- ggplot(marvelTotal[1:20, ], aes(x = reorder(Name, Total), y = Total)) +
geom_bar(stat = "identity", aes(fill = Alignment)) +
labs(x = "Character", y = "Total", title = "Top 20 Marvel Characters", subtitle = "Most Powerful Heroes or Villains") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=goodBadPalette, labels = c("villain", "hero", "neutral"))
grid.arrange(dcTotal, marvelTotal, ncol = 2)
# TOP SUPERPOWERS MARVEL AND DC
dcSuperP <- marvelDc %>%
filter(Publisher == "DC Comics") %>%
group_by(SuperPower) %>%
dplyr::count(SuperPower) %>%
select(SuperPower, Count = n) %>%
arrange(-Count)
dcSuperP <- ggplot(dcSuperP[1:20, ], aes(x = reorder(SuperPower, Count), y = Count)) +
geom_bar(stat = "identity", aes(fill = SuperPower)) +
geom_label(stat = "identity", aes(label = Count)) +
labs(x = "Superpower", y = "No. of Characters", title = "DC Comics", subtitle = "Top 20 Superpowers") +
guides(fill = FALSE) +
coord_flip() +
theme_bw()
marvelSuperP <- marvelDc %>%
filter(Publisher == "Marvel Comics") %>%
group_by(SuperPower) %>%
dplyr::count(SuperPower) %>%
select(SuperPower, Count = n) %>%
arrange(-Count)
marvelSuperP <- ggplot(marvelSuperP[1:20, ], aes(x = reorder(SuperPower, Count), y = Count)) +
geom_bar(stat = "identity", aes(fill = SuperPower)) +
geom_label(stat = "identity", aes(label = Count)) +
labs(x = "Superpower", y = "No. of Characters", title = "Marvel Comics", subtitle = "Top 20 Superpowers") +
guides(fill = FALSE) +
coord_flip() +
theme_bw()
grid.arrange(dcSuperP, marvelSuperP, ncol = 2)
# TOP CHARACTERS HIGHEST No. OF SUPERPOWERS
marvelDcSuperP <- marvelDc %>%
group_by(Name, Publisher) %>%
dplyr::count(Name) %>%
select(Name, Count = n) %>%
arrange(-Count)
ggplot(marvelDcSuperP[1:25, ], aes(x = reorder(Name, Count), y = Count)) +
geom_bar(stat = "identity", aes(fill = Publisher)) +
labs(x = "Character", y = "No. of superpowers", title = "Top 25 Marvel and DC Characters", subtitle = "With Highest No. of Superpowers") +
coord_flip() +
theme_bw() +
scale_fill_manual(values=dcMarvelPalette)