Hi @Nabeegh10,
Sorry, I took each row in your CSV to be a data point. If you're not able to attribute sales to individual promotions, I might try something like this:
install.packages("tidyverse")
install.packages("scales")
install.packages("purrr")
install.packages("ggpattern")
library(tidyverse)
library(scales)
library(purrr)
library(ggpattern)
Date <- c(
'10/27/2021', '10/28/2021', '10/29/2021', '10/30/2021', '10/31/2021', '10/31/2021', '11/1/2021', '11/2/2021', '11/3/2021', '11/4/2021', '11/5/2021', '11/6/2021', '11/6/2021', '11/7/2021'
)
Total_Order <- c(
289, 194, 216, 198, 165, 165, 120, 102, 114, 116, 114, 68, 68, 123
)
Total_Sales <- c(
17190.668, 16882.324, 15238.71, 15453.082, 20830.2122, 20830.2122, 8414.412, 6987.064, 11078.11, 10797.09, 9042.466, 6844.768, 6844.768, 11623.452
)
Events <- c(
'Outlet 40%off', 'Outlet 40%off', 'Outlet 40%off', 'Outlet 40%off', 'Outlet 40%off', 'Holiday Sale', 'Holiday Sale', 'Holiday Sale', 'Candle Sale', 'Candle Sale', 'Candle Sale', 'Candle Sale', 'Holiday Sale', 'Candle Sale'
)
df <-
data.frame(Date = as.Date(Date, format = "%m/%d/%y"), Total_Order, Total_Sales, Events) |>
mutate(color = case_when(
Events == 'Outlet 40%off' ~ "red",
Events == 'Holiday Sale' ~ "blue",
Events == 'Candle Sale' ~ "green"
)) |>
group_by(Date, Total_Order, Total_Sales) |>
summarize(Events = paste(Events, collapse=", "),
colors = list(color)) |>
#ungroup() |>
mutate(pattern = case_when(
lengths(colors) == 1 ~ "blank",
lengths(colors) > 1 ~ "hdashes"
)) |>
mutate(backgroundColor = pluck(colors, 1, 1)) |>
mutate(patternColor = pluck(colors, 1, 2, .default = backgroundColor))
df |>
ggplot(aes(x = Date, y = Total_Sales)) +
geom_col_pattern(
aes(
x = Date,
y = Total_Sales,
pattern_colour = patternColor,
pattern_fill = patternColor,
fill = backgroundColor
),
colour='black',
pattern = "stripe",
pattern_density = 0.5
) +
geom_text(aes(label = scales::dollar(Total_Sales, largest_with_cents = 1)), size = 3, vjust = -0.8) +
theme_minimal() +
theme(
panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank(),
legend.position = "none") +
scale_x_date(date_breaks = "3 days", date_labels = "%b %d") +
scale_y_continuous(labels = scales::dollar) +
labs(
title = "Total Sales by Day",
subtitle = "Broken out by events",
y = "Total Sales"
)
I don't love the ggpattern package since the legends are a mess, but this technically works.