---
title: "Retail Shop"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
theme : yeti
source_code : embed
---
```{r setup, include=FALSE}
pacman::p_load("flexdashboard",
"ggpubr",
"plotly",
"ggplot2",
"readxl",
"tidyverse",
"dplyr",
"prob",
"scales")
```
```{r}
data <- read.csv("C:/Users/valen/Desktop/Flex_Dashboard/Tugas1/data_ecommerce.csv")
```
```{r}
new_data <- separate(data,
col = InvoiceDate,
into = c("Date", "Time"),
sep = " "
)
```
```{r}
new_data_Date <- new_data %>%
count(Date)
new_data_Date1 <- arrange(new_data_Date, desc(n))
datetop10 <- new_data_Date1[1:20,]
```
```{r}
new_data <- separate(new_data,
col = Date,
into = c("Month", "Date", "Year"),
sep = "/"
)
new_data$Price_Total = new_data$Quantity * new_data$UnitPrice
```
Transaksi by Date {data-orientation=rows}
=======================================================================
### Transaksi Berdasarkan Waktu {data-width=1200}
```{r}
ggplot(datetop10, aes(x = Date, y = n)) +
geom_point(color = "deepskyblue",
size = 1,
alpha = .8) +
theme_minimal() +
labs(
x = "Date",
y = "Transaksi") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
France vs Others {data-orientation=rows}
=======================================================================
### Perbandingan Pendapatan Negara France Dengan Negara Lain {data-width=1200}
```{r}
Price <- new_data %>%
count(Country)
Country = c("Australia" , "Austria" , "Bahrain" , "Belgium" , "Brazil" ,
"Canada" , "Channel Islands" , "Cyprus" , "Czech Republic" , "Denmark" ,
"EIRE" , "European Community" , "Finland" , "France" , "Germany" ,
"Greece" , "Hong Kong" , "Iceland" , "Israel" , "Italy" ,
"Japan" , "Lebanon" , "Lithuania" , "Malta" , "Netherlands" ,
"Norway" , "Poland" , "Portugal" , "RSA" , "Saudi Arabia" ,
"Singapore" , "Spain" , "Sweden" , "Switzerland" , "United Arab Emirates",
"United Kingdom", "Unspecified" , "USA" )
pendapatan_negara = data.frame("Negara" = Country,
"Penghasilan" = c(137077.3, 10154.32, 548.4, 40910.96, 1143.6, 3666.38, 20086.29,
12946.29, 707.72, 18768.14, 263276.8, 1291.75, 22326.74, 197403.9,
221698.2, 4710.52, 10117.04, 4310, 7907.82, 16890.51, 35340.62, 1693.88,
1661.06, 2505.47, 284661.5, 35163.46, 7213.14, 29367.02, 1002.31, 131.17,
9120.39, 54774.58, 36595.91, 56385.35, 1902.28, 8187806, 4749.79, 1730.92))
pendapatan = pendapatan_negara%>%
mutate(percent = Penghasilan/sum(Penghasilan),
pert = round(percent,2)*100)
p = subset(pendapatan, subset = Negara!= "France")
pendapatan = data.frame("a" = c("France", "Others"),
"b" = c(84, sum(p$pert)))
pendapatan =pendapatan %>%
mutate(c =cumsum(b) - 0.5*b)
ggplot(pendapatan, aes(x="", y= b, fill=a))+
geom_bar(width=1, stat="identity", color="white") +
coord_polar("y", start = 0) +
geom_text(aes(y= c,label =b), color="white")+
scale_fill_manual(values = c("purple","orange"))+
theme_void()
```
Top 10 Negara Penjualan Terbanyak {data-orientation=rows}
=======================================================================
## Column {.tabset .tabset-fade data-height=520}
-----------------------------------------------------------------------
```{r}
top10 = arrange(pendapatan_negara, desc(Penghasilan))
top10 = top10[2:11,]
```
### horizontal {data-width=1200}
```{r}
ggplot(top10,
aes(x = reorder(Negara,Penghasilan),
y = Penghasilan)) +
geom_bar(stat = "identity",
fill = rainbow(10)) +
geom_text(aes(label = Penghasilan),
vjust = -0.25) +
theme_minimal() +
labs(
x = "negara",
y = "total ($)")+ coord_flip()
```
### vertikal {data-width=1200}
```{r}
ggplot(top10,
aes(x = Penghasilan,
y = reorder(Negara,Penghasilan))) +
geom_bar(stat = "identity",
fill = rainbow(10)) +
geom_text(aes(label = Penghasilan),
vjust = -0.25) +
theme_minimal() +
labs(
x = "total",
y = "negara")+ coord_flip()
```
Banyaknya Transaksi Per Bulan {data-orientation=rows}
=======================================================================
### Banyaknya Transaksi Per Bulannya
```{r}
jeki = new_data %>%
group_by(InvoiceNo, Year, Month)%>%
dplyr::summarise(n= n())
```
```{r}
t_2010 = subset(jeki, subset= Year == 2010)
t_2011 = setdiff(jeki, t_2010)
library(plyr)
a = count(t_2011, "Month")
b = count(t_2010, "Month")
a$Year = 2011
b$Year = 2010
jeki = rbind(a,b)
```
```{r}
ggplot(jeki,
aes(x = reorder(Month,-freq),
y = freq)) +
geom_bar(stat = "identity",
fill = rainbow(13),
color= "azure4") +
geom_text(aes(label = freq),
vjust = -0.25) +
theme_minimal()+
labs(x = "Bulan",
y = "Jumlah Transaksi") +
theme(axis.text.x = element_text(angle=30, hjust = 1))
```