-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
708 lines (643 loc) · 27.7 KB
/
app.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
library(dashBootstrapComponents)
library(reshape2)
library(tidyverse)
library(ggplot2)
library(plotly)
library(dplyr)
library(data.table)
#Create App
app <- Dash$new(external_stylesheets = dbcThemes$BOOTSTRAP)
app$title("Video Game Statistics")
#Read in data/wrangle
#game <- readr::read_csv(here::here('data', 'vgsales.csv'))
game <- read_csv('data/vgsales.csv')
game_melt <- melt(data=game,id.vars = c("Rank","Name","Platform","Year","Genre","Publisher"),measure.vars=c("NA_Sales","EU_Sales","JP_Sales","Other_Sales","Global_Sales"))
game_melt$Year <- as.integer(game_melt$Year)
colnames(game_melt)[7] <- "Region"
colnames(game_melt)[8] <- "Copies_Sold"
#game_melt <- tidyr::gather(game, key = "Region", value = "Sales", NA_Sales, EU_Sales, Global_Sales, JP_Sales, Other_Sales)
#genre_sales <- aggregate(Global_Sales ~ Genre, game, sum)
#sorted_genre_totalsales <- genre_sales[order(-genre_sales$Global_Sales),]$Genre
#Data wrangling
sales_data <- game_melt[!(game_melt$Region=="Global_Sales"),]
#sales_data_platform <- aggregate(Sales ~ Platform+Year+Genre+Region, game_melt, sum)
#sales_data_publisher <- aggregate(Sales ~ Publisher+Year+Genre+Region, game_melt, sum)
top_game_init <- game_melt %>% #Initialize Top Game Card (Tab3)
group_by(Name) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
top_genre_init <- game_melt %>% #Initialize Top Genre Card (Tab3)
group_by(Genre) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
top_platform_init <- game_melt %>% #Initialize Top Platform Card (Tab3)
group_by(Platform) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
top_publisher_init <- game_melt %>% #Initialize Top Publisher Card (Tab3)
group_by(Publisher) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
#Nested Lists for Filters
platform_filter <- unique(game$Platform) %>%
purrr::map(function(col) list(label = col, value = col))
platform_filter <- append(platform_filter,list(list(label="All",value="all")))
genre_filter <- unique(game$Genre) %>%
purrr::map(function(col) list(label = col, value = col))
genre_filter <- append(genre_filter,list(list(label="All",value="all")))
publisher_filter <- unique(game$Publisher) %>%
purrr::map(function(col) list(label = col, value = col))
publisher_filter <- append(publisher_filter,list(list(label="All",value="all")))
## Dropdown modules
dropdown_region = dccDropdown(id='region_selector',
options = list(list(label="North America",value="NA_Sales"),
list(label="Europe",value="EU_Sales"),
list(label="Japan",value="JP_Sales"),
list(label="Other",value="Other_Sales"),
list(label="Global", value = "Global_Sales")),
value='Global_Sales',
multi=TRUE)
dropdown_region_2 = dccDropdown(
id='region_selector2',
options = list(list(label="North America",value="NA_Sales"),
list(label="Europe",value="EU_Sales"),
list(label="Japan",value="JP_Sales"),
list(label="Other",value="Other_Sales"),
list(label="Global", value = "Global_Sales")),
value='Global_Sales',
multi=FALSE)
dropdown_platform = dccDropdown(id='platform_selector',options = platform_filter,value="all",multi=TRUE)
dropdown_genre = dccDropdown(id='genre_selector',options = genre_filter,value="all",multi=TRUE)
dropdown_publisher = dccDropdown(id='publisher_selector',options = publisher_filter,value="all",multi=TRUE)
dropdown_gamechoice = dccDropdown(id='popular_selector',
options = list(list(label="Game Title",value="Game_Title"),
list(label="Publisher",value="Publisher"),
list(label="Platform",value="Platform")),
value='Game_Title',
multi=FALSE)
# Range slider modules
range_slider_timeseries = dccRangeSlider(id = "year_selector",
min = 1980,
max = 2017,
marks = list("1980" = "1980",
"1985" = "1985",
"1990" = "1990",
"1995" = "1995",
"2000" = "2000",
"2005" = "2005",
"2010" = "2010",
"2015" = "2015"),
value = list(1980,2017))
clearing_filters_button = dbcButton("Reset Filters",id="reset_button")
# Collapse buttons
tab1_htu <- htmlDiv(list(
dbcButton("How to use:",
id="tab1-button",
className="mb-3",
color="primary"),
dbcCollapse(
id = "tab1-collapse",
is_open = TRUE,
dbcCard(list(
dbcCardBody(list(
htmlP("- Change the filters on sidebar to desired fields."),
htmlP("- Use the `Reset Filters` button to return to default values."),
htmlP("- Plots will change with the filters on the sidebar."),
htmlP("- You can also filter the plots by clicking on their legends."),
htmlP("- If you put your mouse over any point in the plots, you will see a tooltip with further details."),
htmlP("- Click the legend to remove/isolate variables of interest.")
))
))
)
))
tab2_htu <- htmlDiv(list(
dbcButton("How to use:",
id="tab2-button",
className="mb-3",
color="primary"),
dbcCollapse(
id = "tab2-collapse",
is_open = TRUE,
dbcCard(list(
dbcCardBody(list(
htmlP("- Change the filters on sidebar to desired fields."),
htmlP("- Use the `Reset Filters` button to return to default values."),
htmlP("- Plots will change with the filters on the sidebar."),
htmlP("- You can also filter the plots by clicking on their legends."),
htmlP("- If you put your mouse over any point in the plots, you will see a tooltip with further details."),
htmlP("- Click the legend to remove/isolate variables of interest.")
))
))
)
))
tab3_htu <- htmlDiv(list(
dbcButton("How to use:",
id="tab3-button",
className="mb-3",
color="primary"),
dbcCollapse(
id = "tab3-collapse",
is_open = TRUE,
dbcCard(list(
dbcCardBody(list(
htmlP("- Change the filters on sidebar to desired fields."),
htmlP("- Both cards and plots will change with the filters on the sidebar."),
htmlP("- Use the `Reset Filters` button to return to default values."),
htmlP("- Use the dropdown to change the category of interest for the plot."),
htmlP("- If you put your mouse over any point in the plots, you will see a tooltip with further details."),
htmlP("- Click the legend to remove/isolate variables of interest.")
))
))
)
))
# Tab modules
tab1_components =
htmlDiv(list(
htmlBr(),
htmlH3("Number of Games Released Over the Years"),
dccGraph(id='plot-area2'),
htmlBr(),
htmlH3("Global Number of Genres, Platforms and Publishers"),
dccGraph(id='plot-area3')
))
first_tab_sidebar_Card = dbcCard(
dbcCardBody(htmlDiv(
list(htmlH4("Dashboard for Video Games Statistics")
)
))
)
first_tab_sidebar_Card_2 = dbcCard(
dbcCardBody(htmlDiv(
list(clearing_filters_button,htmlBr(),htmlBr(),
htmlLabel("Select your Region of Interest:"),
dropdown_region,
htmlBr(),
htmlLabel("Select your Platform of Interest:"),
dropdown_platform,
htmlBr(),
htmlLabel("Select your Genre of Interest:"),
dropdown_genre,
htmlBr(),
htmlLabel("Select your Publisher of Interest:"),
dropdown_publisher,
htmlBr(),
htmlLabel('Time Range'),
range_slider_timeseries
)
))
)
first_tab_figures_card = dbcCard(
dbcCardBody(htmlDiv(list(tab1_components))))
row_tab1 = dbcRow(list(
dbcCol(first_tab_sidebar_Card, width = 3),
dbcCol(first_tab_figures_card), width = 9))
tab_1 = dccTab(label='Number of Games Released',children=list(
dbcCard(list(
dbcCardBody(list(
htmlP("This tab contains information regarding the trend of game releases across Genres, Platforms and Publishers."),
htmlP("NOTE: Every game was released in every Region. Therefore, the Region filter will not change these values."),
tab1_htu
))
)),
htmlBr(),
first_tab_figures_card))
tab_2 = dccTab(label='Number of Copies Sold', children=list(
htmlDiv(list(
dbcCard(list(
dbcCardBody(list(
htmlP("This tab contains information regarding the number of copies sold across Genres, Platforms and Publishers."),
tab2_htu
))
)),
htmlBr(),
dbcCard(list(
dbcCardBody(list(
htmlH3("Number of Copies Sold Over the Years"),
dccGraph(id='plot-area'),
htmlBr(),
htmlH3("Total Number of Copies Sold by Genre"),
dccGraph(id='plot-area4')
))
))
))
))
tab_3 = dccTab(label='Top Copies Sold', children=list(
#Information at the Top
htmlDiv(list(
dbcCard(list(
dbcCardBody(list(
htmlP("This tab contains information regarding top Games, Genres, Platforms and Publishers in terms of copies sold."),
tab3_htu
))
)),
htmlBr(),
# Top Score Cards
dbcContainer(list(
dbcRow(list(
dbcCol(list(
dbcCard(list(
dbcCardHeader("Game with Most Copies Sold:"),
dbcCardBody(list(
htmlH5(id="top_game",
top_game_init$Name),
htmlP(id="top_game_sales",
sprintf("%.2f million copies sold",top_game_init$`Copies Sold`))
))
),
color="primary",
inverse=TRUE
),
htmlBr(),
dbcCard(list(
dbcCardHeader("Genre with Most Copies Sold"),
dbcCardBody(list(
htmlH5(id="top_genre",
top_genre_init$Genre),
htmlP(id="top_genre_sales",
sprintf("%.2f million copies sold",top_genre_init$`Copies Sold`))
))
),
color="secondary",
inverse=TRUE
),
htmlBr(),
dbcCard(list(
dbcCardHeader("Platform with Most Copies Sold"),
dbcCardBody(list(
htmlH5(id="top_platform",
top_platform_init$Platform),
htmlP(id="top_platform_sales",
sprintf("%.2f million copies sold",top_platform_init$`Copies Sold`))
))
),
color="info",
inverse=TRUE
),
htmlBr(),
dbcCard(list(
dbcCardHeader("Publisher with Most Copies Sold"),
dbcCardBody(list(
htmlH5(id="top_publisher",
top_publisher_init$Publisher),
htmlP(id="top_publisher_sales",
sprintf("%.2f million copies sold",top_publisher_init$`Copies Sold`))
))
),
color="success",
inverse=TRUE
)
),width = 4),
#Graph
dbcCol(list(
dbcCard(
dbcCardBody(list(
htmlH3(id="graph_5_title"),
htmlBr(),
htmlLabel("Select your choice of interest:"),
dropdown_gamechoice,
dccGraph(id='plot-area5'),
htmlBr()
))
)
))
))
))
))
))
app$layout(dbcRow(list(
dbcCol(list(
htmlDiv(list(first_tab_sidebar_Card, htmlBr(), first_tab_sidebar_Card_2, htmlBr()))),width = 3),
dbcCol(dbcContainer(
(htmlDiv(htmlDiv(list(
dccTabs(id="tabs", children=list(
tab_1,tab_2,tab_3
))
))
))), width = 9)
)))
#Callback for Button
app$callback(
list(output('region_selector', 'value'),
output('platform_selector', 'value'),
output('genre_selector', 'value'),
output('publisher_selector', 'value'),
output('year_selector', 'value')),
list(input('reset_button','n_clicks')),
function(n_clicks){
#Input: if button is clicked
#Output: Default values for all filters
#
#If clicked - return default values to filters
return (list("Global_Sales","all","all","all",list(1980,2017)))
}
)
#Callback for HTU button - Tab 1
app$callback(
list(output("tab1-collapse","is_open")),
list(input("tab1-button","n_clicks"),
state("tab1-collapse","is_open")),
function (n_clicks,is_open){
#Input: Button and State of Collapse
#Output: Opposite of Current State of Collapse
return (list(!is_open))
}
)
#Callback for HTU button - Tab 2
app$callback(
list(output("tab2-collapse","is_open")),
list(input("tab2-button","n_clicks"),
state("tab2-collapse","is_open")),
function (n_clicks,is_open){
#Input: Button and State of Collapse
#Output: Opposite of Current State of Collapse
return (list(!is_open))
}
)
#Callback for HTU button - Tab 3
app$callback(
list(output("tab3-collapse","is_open")),
list(input("tab3-button","n_clicks"),
state("tab3-collapse","is_open")),
function (n_clicks,is_open){
#Input: Button and State of Collapse
#Output: Opposite of Current State of Collapse
return (list(!is_open))
}
)
#Callback for Cards (Tab 3)
app$callback(
list(output('top_game', 'children'),
output("top_game_sales","children"),
output('top_genre','children'),
output('top_genre_sales','children'),
output('top_platform','children'),
output('top_platform_sales','children'),
output('top_publisher','children'),
output('top_publisher_sales','children')),
list(input('region_selector', 'value'),
input('platform_selector', 'value'),
input('genre_selector', 'value'),
input('publisher_selector', 'value'),
input('year_selector', 'value')),
function(reg,plat,gen,pub,years) {
#Input: List of Regions, Platforms, Genres, Publishers, Min and Max Year
#Output: Name & Sales of Top Game
#
if ("Global_Sales" %in% reg){
filter_region = list("Global_Sales")
} else {
filter_region = reg
}
if ("all" %in% plat){
filter_plat = unique(game_melt$Platform)
} else {
filter_plat = plat
}
if ("all" %in% gen){
filter_gen = unique(game_melt$Genre)
} else {
filter_gen = gen
}
if ("all" %in% pub){
filter_pub = unique(game_melt$Publisher)
} else {
filter_pub = pub
}
min_year = years[1]
max_year = years[2]
filtered_subset <- game_melt %>%
subset(Region %in% filter_region & Platform %in% filter_plat & Genre %in% filter_gen & Publisher %in% filter_pub & Year >= min_year & Year <= max_year)
top_game <- filtered_subset %>%
group_by(Name) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
top_genre <- filtered_subset %>%
group_by(Genre) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
top_publisher <- filtered_subset %>%
group_by(Publisher) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
top_platform <- filtered_subset %>%
group_by(Platform) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
subset(`Copies Sold`== max(`Copies Sold`))
return (list(top_game$Name,sprintf("%.2f million copies sold",top_game$`Copies Sold`),
top_genre$Genre,sprintf("%.2f million copies sold",top_genre$`Copies Sold`),
top_platform$Platform,sprintf("%.2f million copies sold",top_platform$`Copies Sold`),
top_publisher$Publisher,sprintf("%.2f million copies sold",top_publisher$`Copies Sold`)))
}
)
#Callback for all plots
app$callback(
list(output('plot-area', 'figure'),
output('plot-area2', 'figure'),
output('plot-area3', 'figure'),
output('plot-area4', 'figure')),
list(input('region_selector', 'value'),
input('platform_selector', 'value'),
input('genre_selector', 'value'),
input('publisher_selector', 'value'),
input('year_selector', 'value')),
function(reg,plat,gen,pub,years) {
# Input: List of Regions, Platforms, Genres, Publishers, Min and Max Year
# Output: Graph
#
# Create subset based on filters
# Pass to graph
# Output graph
if ("Global_Sales" %in% reg){
filter_region = list("Global_Sales")
} else {
filter_region = reg
}
if ("all" %in% plat){
filter_plat = unique(game_melt$Platform)
} else {
filter_plat = plat
}
if ("all" %in% gen){
filter_gen = unique(game_melt$Genre)
} else {
filter_gen = gen
}
if ("all" %in% pub){
filter_pub = unique(game_melt$Publisher)
} else {
filter_pub = pub
}
min_year = years[1]
max_year = years[2]
filtered_game_melt <- game_melt[,3:8] %>%
subset(Region %in% filter_region & Platform %in% filter_plat & Genre %in% filter_gen & Publisher %in% filter_pub & Year >= min_year & Year <= max_year)
graph1 <- filtered_game_melt %>%
group_by(Year,Genre) %>%
summarise("Copies Sold" = sum(`Copies_Sold`)) %>%
ggplot() +
aes(x=as.factor(Year),
y=`Copies Sold`,
fill = Genre,
group = 1,
text = paste("Year: ",as.factor(Year),
"<br>Copies Sold: ",`Copies Sold`,
"<br>Genre: ", Genre)) +
geom_bar(stat="identity")+ #geom_line
theme_bw() +
theme(legend.title=element_blank()) +
theme(panel.grid.major.x = element_blank()) +
theme(axis.text.x = element_text(angle = 90, hjust=0.95, vjust=0.2)) +
#scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
ylab("Number of Copies Sold (in millions)")+
xlab("Year")
graph1 <- ggplotly(graph1,tooltip="text")
graph2 <- filtered_game_melt %>%
group_by(Year,Genre) %>%
count(Year,Genre) %>%
rename(`Number of Releases`="n") %>%
ggplot() +
aes(x=as.factor(Year),
y=`Number of Releases`,
fill = Genre,
group = 1,
text = paste("Year: ",as.factor(Year),
"<br>No. of Games Released: ",`Number of Releases`,
"<br>Genre: ", Genre)) +
geom_bar(stat="identity") + #geom_line
theme_bw() +
theme(legend.title=element_blank()) +
theme(panel.grid.major.x = element_blank()) +
theme(axis.text.x = element_text(angle = 90, hjust=0.95, vjust=0.2))+
#scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
ylab("Number of Games Released")+
xlab("Year")
graph2<-ggplotly(graph2,tooltip="text")
graph3 <- filtered_game_melt %>%
melt(id.vars=c("Year"),measure.vars=c("Genre","Platform","Publisher")) %>%
rename(Category='variable') %>%
group_by(Year,Category) %>%
unique() %>%
count(Year,Category) %>%
rename(`Counts of Genres, Publishers and Platforms`= n) %>%
ggplot() +
aes(x=as.factor(Year),
y=`Counts of Genres, Publishers and Platforms`,
fill = Category,
group = 1,
text = paste("Year: ",as.factor(Year),
"<br>No. of Major Genre, Publishers, Platforms: ",`Counts of Genres, Publishers and Platforms`,
"<br>Category: ", Category)) +
geom_area(stat="identity")+
theme_bw() +
theme(legend.title=element_blank()) +
theme(panel.grid.major.x = element_blank()) +
theme(axis.text.x = element_text(angle = 90, hjust=0.95, vjust=0.2))+
#scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
ylab("Number of Major Genres, Publishers and Platforms")+
xlab("Year")
graph3<-ggplotly(graph3,tooltip="text")
graph4 <- filtered_game_melt %>%
group_by(Genre) %>%
summarize(genre_sales = sum(Copies_Sold)) %>%
ggplot() +
aes(x=reorder(Genre,-genre_sales),
y=genre_sales,
fill=Genre,
text=paste("Genre: ", Genre,
"<br>Copies Sold: ", genre_sales)) +
geom_bar(stat="identity") +
theme_bw() +
theme(panel.grid.major.x = element_blank()) +
theme(legend.position = "none") +
#scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
ylab("Number of Copies Sold (in millions)") +
xlab("Genre")
graph4<- ggplotly(graph4,tooltip="text")
return(list(graph1,graph2,graph3,graph4))
}
)
#Callback for linking time sliders
#Callback for Tab3-Plot1
app$callback(
list(output('plot-area5', 'figure'),
output('graph_5_title','children')),
list(input('popular_selector', 'value')),
function(plot_type) {
# Input: List of Regions
# Output: Graph
sales_sub <- data.table(sales_data, key="Genre")[, head(.SD, 30), by=Genre]
if (plot_type == "Game_Title"){
graph4 <- sales_sub %>%
ggplot() +
aes(x=reorder(Genre,-Copies_Sold),
y=Copies_Sold,
fill = Genre,
color = Genre,
text=paste("Genre: ", Genre,
"<br>Copies Sold: ", Copies_Sold)) +
geom_point() +
geom_text(aes(label=ifelse(Copies_Sold>15,as.character(Name),'')),hjust=-0.1, vjust=0) +
theme(axis.text.x = element_text(angle=45, hjust=0.9, vjust=0.9)) +
theme_bw() +
theme(panel.grid.major.x = element_blank()) +
theme(legend.position = "none") +
theme(axis.title.x = element_blank()) +
#scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
theme(axis.text.x = element_text(angle=45, hjust=0.9, vjust=0.9)) +
ylab("Number of Copies Sold (in millions)") +
xlab("Genre")
title <- "Top Game Titles by Genre"
} else if (plot_type == "Publisher") {
graph4 <- sales_sub %>%
group_by(Genre, Publisher) %>%
summarise(net_sales = sum(Copies_Sold), `.groups` = 'keep') %>%
ggplot() +
aes(x=reorder(Genre,-net_sales),
y=net_sales,
fill = Genre,
color = Genre,
text=paste("Genre: ", Genre,
"<br>Copies Sold: ", net_sales)) +
geom_point() +
geom_text(aes(label=ifelse(net_sales>50,as.character(Publisher),'')),hjust=-0.1, vjust=0) +
theme(axis.text.x = element_text(angle=45, hjust=0.9, vjust=0.9)) +
theme_bw() +
theme(panel.grid.major.x = element_blank()) +
theme(legend.position = "none") +
theme(axis.title.x = element_blank()) +
#scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
theme(axis.text.x = element_text(angle=45, hjust=0.9, vjust=0.9)) +
ylab("Number of Copies Sold (in millions)") +
xlab("Genre")
title <- "Top Publishers by Genre"
} else if (plot_type == "Platform") {
graph4 <- sales_sub %>%
group_by(Genre, Platform) %>%
summarise(net_sales = sum(Copies_Sold), `.groups` = 'keep') %>%
ggplot() +
aes(x=reorder(Genre,-net_sales),
y=net_sales,
fill = Genre,
color = Genre,
text=paste("Genre: ", Genre,
"<br>Copies Sold: ", net_sales)) +
geom_point() +
geom_text(aes(label=ifelse(net_sales>30,as.character(Platform),'')),hjust=-0.1, vjust=0) +
theme_bw() +
theme(panel.grid.major.x = element_blank()) +
theme(legend.position = "none") +
theme(axis.title.x = element_blank()) +
#scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) +
theme(axis.text.x = element_text(angle=45, hjust=0.9, vjust=0.9)) +
ylab("Number of Copies Sold (in millions)") +
xlab("Genre")
title <- "Top Platforms by Genre"
}
return (list(ggplotly(graph4,tooltip="text"),title))
}
)
app$run_server(host = '0.0.0.0')
#app$run_server(debug=T)