The Entertainment Spending Ratio in the total spend is
50.71%.
The dashboard “Spending Habits” was created to analyze the my familay spending trends over the 2019. The dashboard is based on the our own data and was made using the Flexdashboard package with graphs made using Plotty, a gauge representation, and various supporting libraries. The dashboard consists of four tabs, including an overall view, shopping count details, shopping trend details, and spending ratio.
5 questions that can be answered using the dashboard:
1. The three primary shopping categories are Electronic accessories,
Fashion accessories, and Food/beverages.
2. The family entertainment spending ratio is 50.71%.
3. Family spending evenly separated to each category.
4. Each month, the family spending on goods is similar.
5. Electronic accessories spending has higher fluctuation, and it is
likely due to the sale event.
Additionally, 5 Q&A for the dashboard:
What is the purpose of the dashboard “Spending Habits”? Answer: The purpose of the dashboard “Spending Habits” is to analyze the spending trends of a family over the year 2019.
What data is used to create the dashboard? Answer: The dashboard is based on the family’s own data.
What tool was used to create the dashboard? Answer: The dashboard was created using the Flexdashboard package, with graphs made using Plotly and a gauge representation, along with various supporting libraries.
How many tabs does the dashboard include? Answer: The dashboard includes four tabs: Overall, Shopping Count Details, Shopping Trend Details, and Spending Ratio.
What are the three shopping categories analyzed in the dashboard? Answer: The three shopping categories analyzed in the dashboard are Electronic accessories, Fashion accessories, and Food/beverages.
---
title: "ANLY 512 Final Project"
author : "Zhuoqiang Jia"
output:
flexdashboard::flex_dashboard:
vertical_layout: fill
source_code: embed
orientation: columns
theme: cosmo
---
```{r setup, include=FALSE}
library(flexdashboard)
library(dplyr)
library(maps)
library(scatterpie)
library(ggplot2)
library(plotly)
library(rnoaa)
library(usmap)
library(readxl)
library(readr)
library(dygraphs)
library(xts)
library(plotly)
data = read.csv("/Users/zhuoqiangjia/Desktop/HU/2022fall/ANLY 512-90/Final_Project/shopping2019.csv")
```
Overall Dashboard
=====================================
Column {data-width=60%}
-----------------------------------------------------------------------
### Top 3 Shopping item Histogram
```{r}
# Load libraries
library(dplyr)
library(ggplot2)
library(plotly)
# Filter dataset to only include the columns "Shopping Category" and "Date"
data_filtered <- data %>%
select(Shopping.category, Date)
# Convert "Date" column to date type
data_filtered$Date <- as.Date(data_filtered$Date, "%Y/%m/%d")
# Extract the month from the "Date" column
data_filtered$Month <- format(data_filtered$Date, "%m")
# Group the data by "Shopping Category" and "Month"
data_grouped <- data_filtered %>%
group_by(Shopping.category, Month) %>%
summarize(Count = n())
# Get the top 3 shopping categories by sum of "Count"
top3_categories <- data_grouped %>%
group_by(Shopping.category) %>%
summarize(Sum = sum(Count)) %>%
top_n(3, Sum)
# Create a new data frame that only includes the top 3 shopping categories
data_top3 <- data_grouped %>%
filter(Shopping.category %in% top3_categories$Shopping.category)
# Plot the histogram
fig <- ggplot(data_top3, aes(x = Month, y = Count, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
scale_x_discrete(limits = c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")) +
labs(x = "Month", y = "Count") +
theme_minimal() +
ggtitle("2019 Top 3 Shopping Categories Items") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
# Convert the ggplot object to a plotly object
fig <- ggplotly(fig)
# Show the plot
fig
```
### Top 3 Shopping Categories Trent
```{r}
# convert Date to a Date object
data$Date <- as.Date(data$Date, format = "%Y/%m/%d")
# create a month column
data$month <- format(data$Date, "%b")
# get the top 5 categories based on the sum of sales
top_3_categories <- data %>%
group_by(Shopping.category) %>%
summarise(total_sales = sum(Total)) %>%
arrange(desc(total_sales)) %>%
top_n(3) %>%
select(Shopping.category)
# filter the data to only include the top 5 categories
data_filtered_1 <- data %>%
filter(Shopping.category %in% top_3_categories$Shopping.category) %>%
group_by(Shopping.category, month) %>%
summarise(total_sales = sum(Total))
library(plotly)
ggplotly(ggplot(data_filtered_1, aes(x = month, y = total_sales, group=Shopping.category)) +
geom_line(aes(color=Shopping.category)) +
geom_point(aes(color=Shopping.category)) +
labs(x = "Month", y = "Amount in dollors", color = "Shopping Category") +
theme(legend.position = "right") +
theme_minimal())
```
Column {data-width=40%}
-----------------------------------------------------------------------
### Entertainment vs Living Expense Ratio
```{r}
# Calculate the total sales for the three categories
target_categories <- c("Electronic accessories", "Sports and travel", "Fashion accessories")
selected_rows <- data %>%
filter(Shopping.category %in% target_categories)
sum_selected_rows <- sum(selected_rows$Total)
sum_all_rows <- sum(data$Total)
ratio <- sum_selected_rows / sum_all_rows * 100
screening_statement <- sprintf(
"The Entertainment Spending Ratio in the total spend is %s%%.",
round(ratio, 2)
)
# Show average sleep efficiency
enroll_gauge <- gauge(
value = ratio,
min = 0,
max = 100,
label = "Spending Ratio",
gaugeSectors(
success = c(80, 100), warning = c(40, 79), danger = c(0, 39),
))
enroll_gauge
```
<br>
`r screening_statement`
### Representation of Spend by Category
```{r}
#plot
data_all <- data %>%
group_by(Shopping.category) %>%
summarise(Amount = sum(Total))
fig <- plot_ly(data_all, labels = ~Shopping.category, values = ~Amount, type = 'pie')
fig <- fig %>% layout(title = '2019 year',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
```
Shopping Count Details
=====================================
## Column {data-height=900 .tabset .tabset-fade}
### Overall 2019 {data-width=900}
```{r}
# Load libraries
library(dplyr)
library(ggplot2)
library(plotly)
# Get the top 6 shopping categories by sum of "Count"
data_count <- data %>%
group_by(Shopping.category, month) %>%
summarize(Sum = sum(Quantity))
# Plot the histogram
fig <- ggplot(data_count, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("2019 year Shopping Categories Items") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
# Convert the ggplot object to a plotly object
fig <- ggplotly(fig)
# Show the plot
fig
```
### Jan {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Jan",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in January") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Feb {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Feb",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in Febury") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### March {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Mar",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in March") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Apr {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Apr",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in April") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### May {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "May",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in May") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Jun {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Jun",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in June") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Jul {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Jul",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in July") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Aug {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Aug",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in August") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Sep {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Sep",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in September") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Oct {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Oct",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in October") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Nov {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Nov",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in November") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
### Dec {data-width=900}
```{r}
data_count_1 <- data_count[data_count$month == "Dec",]
fig <- ggplot(data_count_1, aes(x = month, y = Sum, fill = Shopping.category)) +
geom_bar(stat = "identity", position="dodge") +
labs(x = "Month", y = "Quantity") +
theme_minimal() +
ggtitle("Shopping Categories Items in December") +
theme(legend.position = "right") +
scale_fill_brewer(palette = "Paired")
fig <- ggplotly(fig)
fig
```
Shopping Trent detials
=====================================
### Shopping Count Details
```{r}
library(plotly)
data$Date <- as.Date(data$Date, format = "%Y/%m/%d")
data$month <- format(data$Date, "%b")
data_filtered <- data %>%
group_by(Shopping.category, month) %>%
summarise(total_sales = sum(Total))
p <- ggplot(data_filtered, aes(x = month, y = total_sales, group=Shopping.category)) +
geom_line(aes(color=Shopping.category)) +
geom_point(aes(color=Shopping.category)) +
labs(x = "Month", y = "Amount in dollars", color = "Shopping Category") +
theme(legend.position = "right") +
theme_minimal()
# convert ggplot to plotly object
p_plotly <- ggplotly(p)
# create the dropdown menu
updatemenus = list(
list(
type = "dropdown",
buttons = list(
list(
args = list(
list(
color = unique(data_filtered$Shopping.category)
)
),
label = unique(data_filtered$Shopping.category),
method = "restyle"
)
),
showactive = T
)
)
# add the dropdown menu to the layout
p_plotly$layout$updatemenus <- updatemenus
# display the plot
p_plotly
```
Shopping Spend Ratio Details
=====================================
Column {data-width=50%}
-----------------------------------------------------------------------
### By Category
```{r}
#plot
fig <- plot_ly(data, labels = ~Shopping.category, values = ~Total, type = 'pie')
fig <- fig %>% layout(title = '2019 year By Category',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
```
Column {data-width=50%}
-----------------------------------------------------------------------
### By Month
```{r}
#plot
fig <- plot_ly(data, labels = ~month, values = ~Total, type = 'pie')
fig <- fig %>% layout(title = '2019 year By Month',
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
fig
```
Summary
=====================================
### Spending Habits
The dashboard "Spending Habits" was created to analyze the my familay spending trends over the 2019. The dashboard is based on the our own data and was made using the Flexdashboard package with graphs made using Plotty, a gauge representation, and various supporting libraries. The dashboard consists of four tabs, including an overall view, shopping count details, shopping trend details, and spending ratio.
5 questions that can be answered using the dashboard:
1. The three primary shopping categories are Electronic accessories, Fashion accessories, and Food/beverages.
2. The family entertainment spending ratio is 50.71%.
3. Family spending evenly separated to each category.
4. Each month, the family spending on goods is similar.
5. Electronic accessories spending has higher fluctuation, and it is likely due to the sale event.
Additionally, 5 Q&A for the dashboard:
What is the purpose of the dashboard "Spending Habits"?
Answer: The purpose of the dashboard "Spending Habits" is to analyze the spending trends of a family over the year 2019.
What data is used to create the dashboard?
Answer: The dashboard is based on the family's own data.
What tool was used to create the dashboard?
Answer: The dashboard was created using the Flexdashboard package, with graphs made using Plotly and a gauge representation, along with various supporting libraries.
How many tabs does the dashboard include?
Answer: The dashboard includes four tabs: Overall, Shopping Count Details, Shopping Trend Details, and Spending Ratio.
What are the three shopping categories analyzed in the dashboard?
Answer: The three shopping categories analyzed in the dashboard are Electronic accessories, Fashion accessories, and Food/beverages.