packages = c('tidyverse', 'lubridate',
'ggthemes', 'reactable',
'reactablefmtr', 'svglite',
'gt', 'gtExtras')
for (p in packages){
if(!require(p, character.only = T)){
install.packages(p)
}
library(p,character.only = T)
}
library(tidyverse)
# library(RODBC)
# con <- odbcConnectAccess('data/Coffee Chain.mdb')
# coffeechain <- sqlFetch(con, 'CoffeeChain Query')
# write_rds(coffeechain, "data/CoffeeChain.rds")
# odbcClose(con)
coffeechain <- read_rds("data/CoffeeChain.rds")
product <- coffeechain %>%
group_by(`Product`) %>%
summarise(`target` = sum(`Budget Sales`),
`current` = sum(`Sales`)) %>%
ungroup()
ggplot(product, aes(Product, current)) +
geom_col(aes(Product, max(target) * 1.01),
fill="grey85", width=0.85) +
geom_col(aes(Product, target * 0.75),
fill="grey60", width=0.85) +
geom_col(aes(Product, target * 0.5),
fill="grey50", width=0.85) +
geom_col(aes(Product, current),
width=0.35,
fill = "black") +
geom_errorbar(aes(y = target,
x = Product,
ymin = target,
ymax= target),
width = .4,
colour = "red",
size = 1) +
coord_flip()

ggplot(sales_report, aes(x=Month, y=Sales)) +
facet_grid(Product ~ ., scales = "free_y") +
geom_ribbon(data = quarts, aes(ymin = quart1, max = quart2),
fill = 'grey90') +
geom_line(size=0.3) +
geom_point(data = mins, col = 'red') +
geom_point(data = maxs, col = 'blue') +
geom_text(data = mins, aes(label = Sales), vjust = -1) +
geom_text(data = maxs, aes(label = Sales), vjust = 2.5) +
geom_text(data = ends, aes(label = Sales), hjust = 0, nudge_x = 0.5) +
geom_text(data = ends, aes(label = Product), hjust = 0, nudge_x = 1) +
expand_limits(x = max(sales_report$Month) +
(0.25 * (max(sales_report$Month) - min(sales_report$Month)))) +
scale_x_continuous(breaks = seq(1, 12, 1)) +
scale_y_continuous(expand = c(0.1, 0)) +
theme_tufte(base_size = 3, base_family = "Helvetica") +
theme(axis.title=element_blank(), axis.text.y = element_blank(),
axis.ticks = element_blank(), strip.text = element_blank())

Product |
Monthly Sales |
Amaretto |
|
Caffe Latte |
|
Caffe Mocha |
|
Chamomile |
|
Colombian |
|
Darjeeling |
|
Decaf Espresso |
|
Decaf Irish Cream |
|
Earl Grey |
|
Green Tea |
|
Lemon |
|
Mint |
|
Regular Espresso |
|
Product |
Min |
Max |
Average |
Amaretto |
1016 |
1210 |
1,119.00 |
Caffe Latte |
1398 |
1653 |
1,528.33 |
Caffe Mocha |
3322 |
3828 |
3,613.92 |
Chamomile |
2967 |
3395 |
3,217.42 |
Colombian |
5132 |
5961 |
5,457.25 |
Darjeeling |
2926 |
3281 |
3,112.67 |
Decaf Espresso |
3181 |
3493 |
3,326.83 |
Decaf Irish Cream |
2463 |
2901 |
2,648.25 |
Earl Grey |
2730 |
3005 |
2,841.83 |
Green Tea |
1339 |
1476 |
1,398.75 |
Lemon |
3851 |
4418 |
4,080.83 |
Mint |
1388 |
1669 |
1,519.17 |
Regular Espresso |
890 |
1218 |
1,023.42 |
Product |
Min |
Max |
Average |
Monthly Sales |
Amaretto |
1016 |
1210 |
1119.000 |
|
Caffe Latte |
1398 |
1653 |
1528.333 |
|
Caffe Mocha |
3322 |
3828 |
3613.917 |
|
Chamomile |
2967 |
3395 |
3217.417 |
|
Colombian |
5132 |
5961 |
5457.250 |
|
Darjeeling |
2926 |
3281 |
3112.667 |
|
Decaf Espresso |
3181 |
3493 |
3326.833 |
|
Decaf Irish Cream |
2463 |
2901 |
2648.250 |
|
Earl Grey |
2730 |
3005 |
2841.833 |
|
Green Tea |
1339 |
1476 |
1398.750 |
|
Lemon |
3851 |
4418 |
4080.833 |
|
Mint |
1388 |
1669 |
1519.167 |
|
Regular Espresso |
890 |
1218 |
1023.417 |
|
bullet <- coffeechain %>%
filter(Date >= "2013-01-01") %>%
group_by(`Product`) %>%
summarise(`Target` = sum(`Budget Sales`),
`Actual` = sum(`Sales`)) %>%
ungroup()
sales_data = sales_data %>%
left_join(bullet)
sales_data %>%
gt() %>%
gt_plt_sparkline('Monthly Sales') %>%
gt_plt_bullet(column = Actual,
target = Target,
width = 28,
palette = c("lightblue",
"black")) %>%
gt_theme_538()
Product |
Min |
Max |
Average |
Monthly Sales |
Actual |
Amaretto |
1016 |
1210 |
1119.000 |
|
|
Caffe Latte |
1398 |
1653 |
1528.333 |
|
|
Caffe Mocha |
3322 |
3828 |
3613.917 |
|
|
Chamomile |
2967 |
3395 |
3217.417 |
|
|
Colombian |
5132 |
5961 |
5457.250 |
|
|
Darjeeling |
2926 |
3281 |
3112.667 |
|
|
Decaf Espresso |
3181 |
3493 |
3326.833 |
|
|
Decaf Irish Cream |
2463 |
2901 |
2648.250 |
|
|
Earl Grey |
2730 |
3005 |
2841.833 |
|
|
Green Tea |
1339 |
1476 |
1398.750 |
|
|
Lemon |
3851 |
4418 |
4080.833 |
|
|
Mint |
1388 |
1669 |
1519.167 |
|
|
Regular Espresso |
890 |
1218 |
1023.417 |
|
|
library(dataui)
report <- report %>%
group_by(Product) %>%
summarize(`Monthly Sales` = list(Sales))
reactable(
report,
columns = list(
Product = colDef(maxWidth = 200),
`Monthly Sales` = colDef(
cell = react_sparkline(report)
)
)
)
reactable(
report,
defaultPageSize = 13,
columns = list(
Product = colDef(maxWidth = 200),
`Monthly Sales` = colDef(
cell = react_sparkline(report)
)
)
)
reactable(
report,
defaultPageSize = 13,
columns = list(
Product = colDef(maxWidth = 200),
`Monthly Sales` = colDef(
cell = react_sparkline(
report,
highlight_points = highlight_points(
min = "red", max = "blue"),
labels = c("first", "last")
)
)
)
)
reactable(
report,
defaultPageSize = 13,
columns = list(
Product = colDef(maxWidth = 200),
`Monthly Sales` = colDef(
cell = react_sparkline(
report,
highlight_points = highlight_points(
min = "red", max = "blue"),
statline = "mean"
)
)
)
)
reactable(
report,
defaultPageSize = 13,
columns = list(
Product = colDef(maxWidth = 200),
`Monthly Sales` = colDef(
cell = react_sparkline(
report,
highlight_points = highlight_points(
min = "red", max = "blue"),
line_width = 1,
bandline = "innerquartiles",
bandline_color = "green"
)
)
)
)
reactable(
report,
defaultPageSize = 13,
columns = list(
Product = colDef(maxWidth = 200),
`Monthly Sales` = colDef(
cell = react_sparkbar(
report,
highlight_bars = highlight_bars(
min = "red", max = "blue"),
bandline = "innerquartiles",
statline = "mean")
)
)
)