-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmazon books Visualization
154 lines (133 loc) · 4.72 KB
/
Amazon books Visualization
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
---
title: "Amazon books Final"
author: "Jeff Fossi"
date: "2022-10-14"
output: html_document
---
```{r}
# Importing libraries
library(flexdashboard)
library(tidyverse)
library(highcharter)
library(gt)
library(htmltools)
library(viridis)
library(readr)
library(dplyr)
```
```{r}
# Importing data
df2 <- read_csv('C:/Users/jmf_a/OneDrive/BDAT 630 Data Visualization/final/AmazonBestSellers2013-2022Books.csv', show_col_types = FALSE)
```
```{r}
head(df2)
```
```{r}
df2 <- select(df2, 'rank', 'title', 'author', 'customerranking', 'customerrankingcount', 'format', 'price', 'year')
```
```{r}
# Removing duplicates
df2 <- df2 %>%
distinct(title, .keep_all = TRUE) %>%
rename(rank = 'rank')
```
```{r}
# remove #, "out of 5 stars" and $ from columns rank customerranking, and price respectively.
df2$rank <- as.numeric(gsub("\\#", "", df2$rank))
#df$customerranking <- gsub(" out of 5 stars", "", as.character((df$customerranking)))
df2$customerranking <- as.numeric(gsub(" out of 5 stars", "", df2$customerranking))
df2$price <- as.numeric(gsub("\\$", "", df2$price))
```
```{r}
# Remove null values.
df2 <- na.omit(df2)
```
```{r}
head(df2)
```
```{r}
# Colors
custom_colors <- viridis::mako(n = 5)
# Most common genre
df2 %>%
group_by(format) %>%
summarise(count = n()) %>%
hchart('pie', hcaes(x = format, y = count, color = custom_colors)) %>%
hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat='<b>Proportion: </b> {point.percentage:,.2f}%') %>%
hc_title(text = 'Most Common format from 2013 to 2022',
style = list(fontSize = '15px', fontWeight = 'bold')) %>%
hc_credits(enabled = FALSE, text = '@jefffossi')
```
```{r}
# Colors
custom_colors <- viridis::mako(n = 15)
# Most popular authors by reviews
df2 %>%
group_by(author) %>%
summarise(Reviews = mean(customerranking)) %>%
arrange(desc(Reviews)) %>%
head(15) %>%
hchart('column', hcaes(x = author, y = Reviews,color = custom_colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Average of Reviews: </b> {point.y} <br>') %>%
hc_title(text = 'Most Popular Authors from 2013 to 2022',
style = list(fontSize = '15px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'By Average of Reviews on Amazon',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = FALSE, text = '@jefffossi')
```
```{r}
# Colors
custom_colors <- viridis::mako(n = 15)
# Most popular authors by reviews
df2 %>%
group_by(author) %>%
summarise(Reviews = sum(customerranking)) %>%
arrange(desc(Reviews)) %>%
head(15) %>%
hchart('column', hcaes(x = author, y = Reviews,color = custom_colors)) %>% hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Total of Reviews: </b> {point.y} <br>') %>%
hc_title(text = 'Most Popular Authors from 2013 to 2022',
style = list(fontSize = '15px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'By Sum of Reviews on Amazon',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = FALSE, text = '@jefffossi')
```
```{r}
# Colors
custom_colors <- viridis::plasma(n = 15)
# Most popular books by reviews
df2 %>%
arrange(desc(customerrankingcount)) %>%
head(15) %>%
hchart('bar', hcaes(x = title, y = customerrankingcount, color = custom_colors)) %>%
hc_add_theme(hc_theme_google()) %>%
hc_tooltip(pointFormat = '<b>Number of Reviews: </b> {point.y} <br>') %>%
hc_title(text = 'Most Popular Books from 2013 to 2022',
style = list(fontSize = '25px', fontWeight = 'bold')) %>%
hc_subtitle(text = 'By Number of Reviews',
style = list(fontSize = '16px')) %>%
hc_credits(enabled = TRUE, text = '@jefffossi')
```
```{r}
# This is going to be a datatable
df3 <- df2 %>%
filter(customerranking >= 4.9) %>%
arrange(desc(customerrankingcount)) %>%
select(title, author)
# HTML table
div(style = 'height:600px; overflow-y:scroll', gt(df3) %>%
tab_header(title = md('Best Books from 2013 to 2022'),
subtitle = md('By Users Rating')) %>%
opt_table_font(font = list(google_font('Chivo'), default_fonts())) %>%
tab_style(location = cells_column_labels(columns = everything()),
style = list(cell_borders(sides = 'bottom',
weight = px(2)),
cell_text(weight = 'bold'))) %>%
tab_options(table.font.size = px(12L),
table.border.top.style = 'none',
column_labels.border.bottom.width = 2,
table_body.border.top.style = 'none',
data_row.padding = px(3))
)
```