-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrand_dash.qmd
359 lines (263 loc) · 8.89 KB
/
brand_dash.qmd
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
---
title: "Brand Reviews"
format:
dashboard:
orientation: columns
nav-buttons: [github]
github: https://github.com/NicolaRizzitello/dash_brand
theme:
- sketchy
- dashstyle.scss
logo: images/tecnology.jpg
logo-alt: Logo with many devices.
---
```{r}
#| label: load-packages
#| message: false
library(paletteer)
library(tidyverse)
library(readxl)
library(lubridate)
library(kableExtra)
library(sqldf)
library(scales)
library(DT)
library(plotly)
library(gt)
#library(ggiraph)
library(showtext)
theme_set(theme_minimal(base_size = 24, base_family = "Atkinson Hyperlegible"))
font_add_google("Montserrat")
showtext_auto()
```
```{r}
#| title: load-data
#| message: false
items<-read.csv("items.csv", h=T, stringsAsFactors = FALSE)
reviews<-read.csv("reviews.csv", h=T, stringsAsFactors = FALSE)
df<-items%>%
inner_join(reviews, c("asin"="asin"))
df <- subset(df, select = -c(url, image, reviewUrl))
```
# {.sidebar}
This dashboard displays statistics for brand's reviews, rate and prices. This dataset is composed by 82815 observations and 9 columns:
| Column name | Description |
|-------------------|-------------------------------------|
| **Asin** | Unique ID |
| **Brand** | Brand Device |
| **Rating** | Average device rate |
| **Title** | Device Name |
| **Total Reviews** | Total of reviews about that device |
| **Prices** | Device price |
| **Date** | Date reviews |
| **Body** | Content review |
| **Name** | Name of person who wrote the review |
# 📁Data
```{r}
df_sub<-df %>%
select(brand, totalReviews, name,prices, date, rating.y)
df_sub %>%
datatable(
colnames = c("Brand", "Total Reviews", "Name", "Prices", "Date", "Votes"),
options = list(dom = 'ftp', paging = TRUE)
)
```
# 📱Brand Reviews and Rate
## Column - Plots {height="50%"}
### Reviews Brand Devices Percentage
::: {.card title="Reviews Brand Devices Percentage"}
```{r}
#| label: Reviews Brand Devices Percentage
#| fig-asp: 2
#| fig-width: 14
n <- length(df$brand)##DIMENSIONE VARIABILE BRAND
brand<-df%>%
group_by(brand)%>%
summarise(n=(n()/n))##CALCOLO DISTRIBUZIONE DI FREQUENZA RELATIVA
p_1 <- ggplot(brand, aes(x = reorder(brand, -n), y=n, fill=brand))
p_1 <- p_1 + geom_bar(stat = "identity") +
#labs(title = "Brand Devices Percentage")+
ylab("Percentage")+
xlab("Brands") + scale_x_discrete(guide = guide_axis(angle = 45)) +
scale_fill_brewer(palette = "Paired",name = "Brand") + scale_y_continuous(labels = scales::percent) + theme_minimal()+theme(text=element_text(size=10,face = "bold",family="Montserrat"))+theme(legend.position="none")
ggplotly(p_1)
```
:::
### Brand Devices Rates {height="50%"}
```{r}
#| title: Brand Devices Rates
#| fig-asp: 2
#| fig-width: 14
p_2 <- ggplot(data = df) +
geom_boxplot(aes(x=brand,y=rating.x, fill = brand)) +
#labs(title = "Brand Devices Rates")+
ylab("Rate")+
xlab("Brands") +
scale_x_discrete(guide = guide_axis(angle = 45)) +
scale_fill_brewer(palette = "Paired") + theme_minimal()+theme(text=element_text(size=10,face = "bold",family="Montserrat"))+theme(legend.position="none")
ggplotly(p_2)
```
## Value Boxes {width="35%"}
### Row - Value boxes {height="30%"}
```{r}
#| label: brand-with-most-reviews
brand_most_rev<-df %>% group_by(brand) %>%
summarise(n = n()) %>%
filter(n == max(n))
device_most_rev<-df %>% group_by(title.x) %>%
summarise(n = n()) %>%
filter(n == max(n))
device_most_rev[c('Title', 'X')] <- str_split_fixed(device_most_rev$title.x, ',', 2)
brand_best_rate<-df %>% group_by(brand) %>%
summarise(n = mean(rating.x)) %>%
filter(n == max(n))
```
::: {.valuebox icon="award-fill" color="#FF7F00"}
Most Brand Reviews:
`{r} brand_most_rev$n`
`{r} brand_most_rev$brand`
:::
::: {.valuebox icon="award-fill" color="#B2DF8A"}
Most Device Reviews:
`{r} device_most_rev$n`
`{r} device_most_rev$Title`
:::
::: {.valuebox icon="award-fill" color="#6A3D9A"}
Mean High Brand Rate:
`{r} round(brand_best_rate$n,2)`
`{r} brand_best_rate$brand`
:::
### Row - Tabsets of tables {.tabset height="70%"}
::: {.card title="Reviews by Brand"}
Brands sorted in descending order of total reviews.
```{r}
#| label: percentage-reviews-by-brand
n <- length(df$brand)##DIMENSIONE VARIABILE BRAND
brand<-df%>%
group_by(brand)%>%
summarise(n=(n()/n)*100) %>% ##CALCOLO DISTRIBUZIONE DI FREQUENZA RELATIVA
arrange(desc(n))
colnames(brand) <- c("Brand", "Perc")
brand$Perc <- round(brand$Perc,2)
# brand<-brand %>%
# gt() %>%
# cols_align(align = "left", column = "Brand") %>%
# data_color(
# method = "numeric",
# palette = "nord::aurora"
# )
# brand
#
#
datatable(brand, filter="none", selection="multiple",escape=FALSE, options = list(dom = 'ltipr'))
```
:::
::: {.card title="Rate by Brand"}
Brands sorted in descending order of best mean rate.
```{r}
#| label: rate-by-brand
brand_rat<-df%>%
group_by(brand)%>%
summarise(n_r = round(mean(rating.x),2)) %>%
arrange(desc(n_r))
colnames(brand_rat) <- c("Brand", "Rate")
# brand_rat<-brand_rat %>%
# gt() %>%
# cols_align(align = "left", column = "Brand") %>%
# data_color(
# method = "numeric",
# palette = "nord::aurora"
# )
# brand_rat
datatable(brand_rat, filter="none", selection="multiple",escape=FALSE, options = list(dom = 'ltipr'))
```
:::
# 💰Price Brand Distribution
## Column - Plots {height="50%"}
### Prices by brand distribution
```{r}
#| label: price-by-brand
#| title: Distribution of prices by brand
#| fig-asp: 2
#| fig-width: 14
df$prices<-gsub("^.{0,1}","",df$prices)###ELIMINO SIMBOLO DOLLARO DALLA VARIABILE PRICES
df$prices<- as.numeric(df$prices)###TRASFORMO LA VARIABILE PRICES IN NUMERIC
p_4<-ggplot(data = df) +
geom_boxplot(aes(x = brand , y = prices, fill = brand)) +
labs(x="Brand", y="Price")+
scale_x_discrete(guide = guide_axis(angle = 45)) +
scale_fill_brewer(palette = "Paired") + theme_minimal()+theme(text=element_text(size=10,family="Montserrat", face = "bold"))+theme(legend.position="none")###RAPPRESENTAZIONE GRAFICA DEI PREZZI PER BRAND
ggplotly(p_4)
```
### Column {height="50%"}
::: {.card title="Price by Brand over Year"}
For some brand there are not data about price from 2014
```{r}
#| label: price-by-brand-year
#| fig-asp: 1
#| fig-width: 10
options(scipen=999)
df$date<-mdy(df$date)###TRASFORMAZIONE VARIABILE DATA
df<-mutate(df, year = year(date))###CREAZIONE VARIBILE YEAR
d_b_r<-df%>%
select(year,brand,prices)%>%
filter(year>="2014")###SELZIONI LE VARIBILI NECESSARIE PER L'ANALISI E FILTRO RISPETTO AL 2014
d_b_r<-d_b_r%>%
group_by(year,brand)%>%
summarise(mean_price=mean(prices,na.rm = TRUE))##CALCOLO TOTALE DELLE REVIEWS PER ANNO E PER BRAND
p_5<-d_b_r %>% ggplot()+
geom_line(mapping = aes(x=year,y=mean_price, color = brand) )+
scale_color_manual(values = c("#A6CEE3" ,"#1F78B4" ,"#B2DF8A" ,"#33A02C" ,"#FB9A99" ,"#E31A1C", "#FDBF6F","#FF7F00" ,"#CAB2D6","#6A3D9A")) +
labs(x="Year", y = "Totale review")+
theme_minimal()+theme(text=element_text(face = "bold",family="Montserrat"))+theme(legend.position="bottom")
ggplotly(p_5)
```
:::
## Value Boxes {width="35%"}
### Row - Value boxes {height="30%"}
```{r}
#| label: brand-with-high-price
brand_most_price<-df %>% group_by(brand) %>%
summarise(n = max(prices,na.rm = TRUE)) %>%
filter(n==max(n))
device_most_price<-df %>% group_by(title.x) %>%
summarise(n = max(prices)) %>%
filter(n == max(n,na.rm = TRUE))
device_most_price$Title <- "Apple iPhone XS Max"
brand_ch_price<-df %>% group_by(brand) %>%
summarise(n = min(prices,na.rm = TRUE)) %>%
filter(n==min(n))
device_ch_price<-df %>% group_by(title.x) %>%
summarise(n = min(prices)) %>%
filter(n == min(n,na.rm = TRUE))
device_ch_price$Title <- "Modem 3G GSM Huawei"
```
::: {.valuebox icon="award-fill" color="#A6CEE3"}
Higher Price Device:
`{r} brand_most_price$n` €
`{r} device_most_price$Title`
:::
::: {.valuebox icon="award-fill" color="#33A02C"}
Cheaper Price Device:
`{r} device_ch_price$n` €
`{r} device_ch_price$Title`
:::
### Row - Tabsets of tables {.tabset height="70%"}
::: {.card title="Higher Price by Brand"}
```{r}
#| label: price-high-by-brand
brand_most_price<-df %>% group_by(brand) %>%
summarise(n = max(prices,na.rm = TRUE))
colnames(brand_most_price) <- c("Brand", "High Price")
datatable(brand_most_price, filter="none", selection="multiple",escape=FALSE, options = list(dom = 'ltipr'))
```
:::
::: {.card title="Cheaper Price by Brand"}
```{r}
#| label: price-cheap-by-brand
brand_ch_price<-df %>% group_by(brand) %>%
summarise(n = min(prices,na.rm = TRUE))
colnames(brand_ch_price) <- c("Brand", "Cheap Price")
datatable(brand_ch_price, filter="none", selection="multiple",escape=FALSE, options = list(dom = 'ltipr'))
```
:::