下午好,
我正在尝试根据以下数据在 R Studio 中创建一些图:
structure(list(Transaction = c(1L, 2L, 2L, 3L, 3L, 3L), Item = c("Bread",
"Scandinavian", "Scandinavian", "Hot chocolate", "Jam", "Cookies"
), period_day = c("morning", "morning", "morning", "morning",
"morning", "morning"), weekday_weekend = c("weekend", "weekend",
"weekend", "weekend", "weekend", "weekend"), Month = c("October",
"October", "October", "October", "October", "October"), Time = c("09",
"10", "10", "10", "10", "10")), row.names = c(NA, 6L), class = "data.frame")
我正在尝试创建条形图以直观地探索数据,例如,我想绘制:
- 每月交易。
- 一天中每个时间的交易(早上、下午、晚上和晚上)。
- 一天中每小时的交易(01、02、03 等)。
- 每个工作日/周末的交易。
例如:
我怎样才能开始制作这些地块?我尝试了以下代码:
SalesByTime <- bb_raw %>%
group_by(Time, Item) %>%
summarise(Transactions = sum(Item))
但我相信这是交易数量的总和,而不是销售频率(见下文)。
structure(list(Time = c("01", "07", "08", "09", "10", "11", "12",
"13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"
), Transactions = c(4090L, 59889L, 3143112L, 9168556L, 12679593L,
15159832L, 14129139L, 13231165L, 13633823L, 11081386L, 7053231L,
1969450L, 289382L, 223385L, 104967L, 16411L, 76746L, 22825L)), row.names = c(NA,
-18L), class = c("tbl_df", "tbl", "data.frame"))
有什么建议么?任何帮助将不胜感激。如果我可以提供更多信息,请告诉我。