library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
set.seed(1)
categories <- c(
"Cross Country Race","Elite Road","Trail","Endurance Road",
"Over Mountain","Triathalon","Sport","Cyclocross","Fat Bike"
)
orders <- expand.grid(
order_date = seq.Date(as.Date("2011-01-01"), as.Date("2015-01-01"), by = "3 months"),
category2 = categories
) %>%
as_tibble() %>%
mutate(
sales = case_when(
category2 == "Fat Bike" ~ runif(n(), 0, 300000),
category2 == "Cross Country Race" ~ runif(n(), 200000, 1500000),
category2 == "Trail" ~ runif(n(), 150000, 900000),
category2 == "Over Mountain" ~ runif(n(), 100000, 850000),
TRUE ~ runif(n(), 50000, 600000)
)
)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
ggplot(orders, aes(x = order_date, y = sales, color = category2)) +
geom_line() +
geom_point(size = 2) +
facet_wrap(~ category2, scales = "free_y") +
scale_y_continuous(labels = dollar_format()) +
labs(
x = "order_date",
y = "Sales"
) +
theme_minimal(base_size = 14) +
theme(
legend.position = "none",
strip.background = element_rect(fill = "#2F4050"),
strip.text = element_text(color = "white", size = 11),
panel.grid.minor = element_blank()
)
