install.packages("readxl")
library(readxl)
library(dplyr)
library(ggplot2)
sales_data <- read_excel("各商户销售与入退场情况.xls")
huangjihuang_data <- read_excel("黄记煌每日销售情况.xls")
tax_data <- read_excel("税收消费情况.xls")
sales_data <- sales_data %>%
mutate(
"2021年1月" = as.Date("2021-01-01"),
"2022年1月" = as.Date("2022-01-01"),
"2022年2月" = as.Date("2022-02-01"),
"2022年3月" = as.Date("2022-03-01"),
"2022年4月" = as.Date("2022-04-01"),
"2022年5月" = as.Date("2022-05-01"),
"2022年6月" = as.Date("2022-06-01"),
"2022年7月" = as.Date("2022-07-01"),
"Monday, August 01, 2022" = as.Date("2022-08-01"),
"Sunday, August 01, 2021" = as.Date("2021-08-01"),
"Thursday, September 01, 2022" = as.Date("2022-09-01"),
"Wednesday, September 01, 2021" = as.Date("2021-09-01"),
"Saturday, October 01, 2022" = as.Date("2022-10-01"),
"Friday, October 01, 2021" = as.Date("2021-10-01"),
"Tuesday, November 01, 2022" = as.Date("2022-11-01"),
"Monday, November 01, 2021" = as.Date("2021-11-01"),
"Thursday, December 01, 2022" = as.Date("2022-12-01"),
"Wednesday, December 01, 2021" = as.Date("2021-12-01")
)
huangjihuang_data <- huangjihuang_data %>%
mutate(交易日期 = as.Date(交易日期))
huangjihuang_ts <- huangjihuang_data %>%
group_by(交易日期) %>%
summarise(总销售额 = sum(交易金额)) %>%
ungroup()
ggplot(huangjihuang_ts, aes(x = 交易日期, y = 总销售额)) +
geom_line() +
labs(
title = "黄记煌每日销售额",
x = "交易日期",
y = "总销售额"
)
sales_ts <- sales_data %>%
pivot_longer(
cols = c(
"2021年1月", "2022年1月", "2022年2月", "2022年3月",
"2022年4月", "2022年5月", "2022年6月", "2022年7月",
"Monday, August 01, 2022", "Sunday, August 01, 2021",
"Thursday, September 01, 2022", "Wednesday, September 01, 2021",
"Saturday, October 01, 2022", "Friday, October 01, 2021",
"Tuesday, November 01, 2022", "Monday, November 01, 2021",
"Thursday, December 01, 2022", "Wednesday, December 01, 2021"
),
names_to = "交易日期",
values_to = "销售额"
) %>%
mutate(销售额 = as.numeric(gsub(",", "", 销售额)))
ggplot(sales_ts, aes(x = 交易日期, y = 销售额, color = 商户)) +
geom_line() +
labs(
title = "各商户每月销售额",
x = "交易日期",
y = "销售额"
)
ggplot(tax_data, aes(x = Month, y = `2022年营收`, fill = Month)) +
geom_bar(stat = "identity") +
labs(
title = "2022年每月税收消费情况",
x = "月份",
y = "营收"
)
huangjihuang_ts <- huangjihuang_ts %>%
mutate(月份 = format(交易日期, "%m"))
ggplot(huangjihuang_ts, aes(x = 月份, y = 总销售额)) +
geom_boxplot() +
labs(
title = "黄记煌每月销售额箱线图",
x = "月份",
y = "总销售额"
)
sales_ts <- sales_ts %>%
filter(交易日期 >= as.Date("2022-01-01")) %>%
group_by(商户) %>%
mutate(增长率 = (销售额 - lag(销售额)) / lag(销售额) * 100)
ggplot(sales_ts, aes(x = 交易日期, y = 增长率, color = 商户)) +
geom_line() +
labs(
title = "各商户每月销售额增长率",
x = "交易日期",
y = "增长率"
)