library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.6 v purrr 0.3.4
## v tibble 3.1.7 v dplyr 1.0.9
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(odbc)
library(RODBC)
library(DBI)
library(ggrepel)
library(forcats)
library(ggthemes)
library(RColorBrewer)
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
options(scipen = 999)
con <- odbcConnect("SQL Server_R")
bikeStores <- sqlQuery(con, "SELECT pc.category_name,
ss.store_name,
ss.city,
ss.state,
SUM(pp.list_price * ps.quantity) grand_sales_totals
FROM production.categories pc
JOIN production.products pp
ON pc.category_id = pp.category_id
JOIN production.stocks ps
ON pp.product_id = ps.product_id
JOIN sales.stores ss
ON ps.store_id = ss.store_id
GROUP BY pc.category_name, ss.store_name, ss.city, ss.state
ORDER BY grand_sales_totals DESC;")
bikeStores <- bikeStores %>%
mutate(grand_sales_totals = grand_sales_totals / 1000000) %>%
mutate(perc = grand_sales_totals / sum(grand_sales_totals) * 100) %>%
arrange(desc(grand_sales_totals))
bikeStores$perc <- round(bikeStores$perc, 2)
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.476344 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.204029 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.143859 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.482206 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.391916 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.387846 7.00
str(bikeStores)
## 'data.frame': 21 obs. of 6 variables:
## $ category_name : chr "Road Bikes" "Road Bikes" "Road Bikes" "Mountain Bikes" ...
## $ store_name : chr "Baldwin Bikes" "Rowlett Bikes" "Santa Cruz Bikes" "Rowlett Bikes" ...
## $ city : chr "Baldwin" "Rowlett" "Santa Cruz" "Rowlett" ...
## $ state : chr "NY" "TX" "CA" "TX" ...
## $ grand_sales_totals: num 2.48 2.2 2.14 1.48 1.39 ...
## $ perc : num 12.49 11.12 10.82 7.48 7.02 ...
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.476344 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.204029 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.143859 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.482206 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.391916 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.387846 7.00
bikeStores$grand_sales_totals <- round(bikeStores$grand_sales_totals, 2)
#biketores totals
bsAggs <- bikeStores %>%
group_by(category_name) %>%
summarise(catTot = sum(grand_sales_totals), catAvg = mean(grand_sales_totals),
n()) %>%
arrange(desc(catTot))
bsAggs$catAvg <- round(bsAggs$catAvg, 2)
bsAggs <- bsAggs %>%
mutate(catTotPerc = catTot / sum(catTot) * 100) %>%
arrange(desc(catTotPerc))
bsAggs$catTotPerc <- round(bsAggs$catTotPerc, digits = 2)
head(bsAggs)
## # A tibble: 6 x 5
## category_name catTot catAvg `n()` catTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Road Bikes 6.82 2.27 3 34.4
## 2 Mountain Bikes 4.19 1.4 3 21.2
## 3 Electric Bikes 3.68 1.23 3 18.6
## 4 Cruisers Bicycles 2.48 0.83 3 12.5
## 5 Cyclocross Bicycles 1.03 0.34 3 5.2
## 6 Comfort Bicycles 0.88 0.29 3 4.44
storeAggs <- bikeStores %>%
group_by(store_name) %>%
summarise(storeTot = sum(grand_sales_totals), storeAvg = mean(grand_sales_totals),
n()) %>%
arrange(desc(storeTot))
head(storeAggs)
## # A tibble: 3 x 4
## store_name storeTot storeAvg `n()`
## <chr> <dbl> <dbl> <int>
## 1 Rowlett Bikes 6.85 0.979 7
## 2 Baldwin Bikes 6.48 0.926 7
## 3 Santa Cruz Bikes 6.48 0.926 7
storeAggs$storeAvg <- round(storeAggs$storeAvg, 2)
storeAggs <- storeAggs %>%
mutate(storeTotPerc = storeTot / sum(storeTot) * 100) %>%
arrange(desc(storeTotPerc))
storeAggs$storeTotPerc <- round(storeAggs$storeTotPerc, 2)
head(storeAggs)
## # A tibble: 3 x 5
## store_name storeTot storeAvg `n()` storeTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Rowlett Bikes 6.85 0.98 7 34.6
## 2 Baldwin Bikes 6.48 0.93 7 32.7
## 3 Santa Cruz Bikes 6.48 0.93 7 32.7
cityAggs <- bikeStores %>%
group_by(city) %>%
summarise(cityTot = sum(grand_sales_totals), cityAvg = mean(grand_sales_totals),
n()) %>%
arrange(desc(cityTot))
head(cityAggs)
## # A tibble: 3 x 4
## city cityTot cityAvg `n()`
## <chr> <dbl> <dbl> <int>
## 1 Rowlett 6.85 0.979 7
## 2 Baldwin 6.48 0.926 7
## 3 Santa Cruz 6.48 0.926 7
cityAggs <- cityAggs %>%
mutate(cityTotPerc = cityTot / sum(cityTot) * 100) %>%
arrange(desc(cityTotPerc))
cityAggs$cityTotPerc <- round(cityAggs$cityTotPerc, 2)
head(cityAggs)
## # A tibble: 3 x 5
## city cityTot cityAvg `n()` cityTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Rowlett 6.85 0.979 7 34.6
## 2 Baldwin 6.48 0.926 7 32.7
## 3 Santa Cruz 6.48 0.926 7 32.7
stateAggs <- bikeStores %>%
group_by(state) %>%
summarise(stateTot = sum(grand_sales_totals), stateAvg = mean(grand_sales_totals),
n()) %>%
arrange(desc(stateTot))
head(stateAggs)
## # A tibble: 3 x 4
## state stateTot stateAvg `n()`
## <chr> <dbl> <dbl> <int>
## 1 TX 6.85 0.979 7
## 2 CA 6.48 0.926 7
## 3 NY 6.48 0.926 7
stateAggs <- stateAggs %>%
mutate(stateTotPerc = stateTot / sum(stateTot) * 100) %>%
arrange(desc(stateTotPerc))
stateAggs$stateTotPerc <- round(stateAggs$stateTotPerc, 2)
head(stateAggs)
## # A tibble: 3 x 5
## state stateTot stateAvg `n()` stateTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 TX 6.85 0.979 7 34.6
## 2 CA 6.48 0.926 7 32.7
## 3 NY 6.48 0.926 7 32.7
#Totals by category asc
head(bsAggs)
## # A tibble: 6 x 5
## category_name catTot catAvg `n()` catTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Road Bikes 6.82 2.27 3 34.4
## 2 Mountain Bikes 4.19 1.4 3 21.2
## 3 Electric Bikes 3.68 1.23 3 18.6
## 4 Cruisers Bicycles 2.48 0.83 3 12.5
## 5 Cyclocross Bicycles 1.03 0.34 3 5.2
## 6 Comfort Bicycles 0.88 0.29 3 4.44
bsAggs %>%
ggplot(aes(fct_reorder(category_name, catTot), catTot, fill = category_name)) +
geom_col() +
theme_clean() +
theme(legend.position = 0) +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES", subtitle = "By category (Millions U.S$)") +
geom_text(mapping = aes(label = paste("$", catTot), vjust = 1)) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category desc
head(bsAggs)
## # A tibble: 6 x 5
## category_name catTot catAvg `n()` catTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Road Bikes 6.82 2.27 3 34.4
## 2 Mountain Bikes 4.19 1.4 3 21.2
## 3 Electric Bikes 3.68 1.23 3 18.6
## 4 Cruisers Bicycles 2.48 0.83 3 12.5
## 5 Cyclocross Bicycles 1.03 0.34 3 5.2
## 6 Comfort Bicycles 0.88 0.29 3 4.44
bsAggs %>%
ggplot(aes(fct_reorder(category_name, - catTot), catTot, fill = category_name)) +
geom_col() +
theme_clean() +
theme(legend.position = 0) +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES", subtitle = "By category (Millions U.S$)") +
geom_text(mapping = aes(label = paste("$", catTot), vjust = 1)) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category percentage asc
bsAggs %>%
ggplot(aes(fct_reorder(category_name, catTotPerc), catTotPerc, fill = category_name)) +
geom_col() +
theme_clean() +
theme(legend.position = 0) +
xlab("CATEGORY") +
ylab("Percentage of total") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category percentage") +
geom_text(mapping = aes(label = paste(catTotPerc, "%"), vjust = 1)) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by category percentage desc
bsAggs %>%
ggplot(aes(fct_reorder(category_name, - catTotPerc), catTotPerc, fill = category_name)) +
geom_col() +
theme_clean() +
theme(legend.position = 0) +
xlab("Category") +
ylab("Percentage of total") +
ggtitle("BIKESTORE's SALES",
subtitle = "By category percentage") +
geom_text(mapping = aes(label = paste(catTotPerc, "%"), vjust = 1)) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Total sales by category and store asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, grand_sales_totals),
grand_sales_totals, fill = store_name)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and store totals (Millions U.S$)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category and store desc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, - grand_sales_totals),
grand_sales_totals, fill = store_name)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and store totals (Millions U.S$)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category and store percentage contributions asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, perc), perc, fill = store_name)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("Percentage $s") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and store totals (%s)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by category and store percentage contributions desc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, - perc), perc, fill = store_name)) +
geom_col() +
theme_clean() +
xlab("CATEGORY") +
ylab("% of grand sales total") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and store totals (%s)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by category and city asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, grand_sales_totals),
grand_sales_totals, fill = city)) +
geom_col() +
theme_clean() +
xlab("CATEGORY") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES PROJECTIONS",
subtitle = "By category and city totals (Millions U.S$)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category and city desc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, - grand_sales_totals),
grand_sales_totals, fill = city)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and city totals (Millions U.S$)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category and city percentages asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, perc),
perc, fill = city)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("% of grand sales total") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and city totals (%s)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by category and city percentage asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, - perc),
perc, fill = city)) +
geom_col() +
theme_clean() +
xlab("CATEGORY") +
ylab("% of grand sales total") +
ggtitle("BIKESTORE'S SALES PROJECTIONS",
subtitle = "By category and city totals (%s)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by category and state asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, grand_sales_totals),
grand_sales_totals, fill = state)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and state totals (Millions U.S$)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category and state amounts desc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, - grand_sales_totals),
grand_sales_totals, fill = state)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and state totals (Millions U.S$)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by category and state percentages asc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, perc),
perc, fill = state)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("% of grand sales total") +
ggtitle("BIKESTORE'S SALES PROJECTIONS",
subtitle = "By category and state (% of grand sales total)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by category and state percentages desc
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(category_name, - perc),
perc, fill = state)) +
geom_col() +
theme_clean() +
xlab("Category") +
ylab("% of grand sales total") +
ggtitle("BIKESTORE'S SALES",
subtitle = "By category and state (% of grand sales total)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")),
vjust = 1, stat = "identity",
position_stack()) +
theme(axis.text.x = element_text(face = "bold", angle = 30, hjust = 1)) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by store asc
head(storeAggs)
## # A tibble: 3 x 5
## store_name storeTot storeAvg `n()` storeTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Rowlett Bikes 6.85 0.98 7 34.6
## 2 Baldwin Bikes 6.48 0.93 7 32.7
## 3 Santa Cruz Bikes 6.48 0.93 7 32.7
storeAggs %>%
ggplot(aes(fct_reorder(store_name, storeTot),
storeTot, fill = store_name)) +
geom_col() +
theme_clean() +
geom_text(aes(label = paste("$", storeTot), vjust =1)) +
ggtitle("BIKESTORE'S SALES", subtitle = " By vendor partner (Millions U.S$)") +
xlab("Store") +
ylab("Sales (millions)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by store desc
head(storeAggs)
## # A tibble: 3 x 5
## store_name storeTot storeAvg `n()` storeTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Rowlett Bikes 6.85 0.98 7 34.6
## 2 Baldwin Bikes 6.48 0.93 7 32.7
## 3 Santa Cruz Bikes 6.48 0.93 7 32.7
storeAggs %>%
ggplot(aes(fct_reorder(store_name, - storeTot),
storeTot, fill = store_name)) +
geom_col() +
theme_clean() +
geom_text(aes(label = paste("$", storeTot), vjust =1)) +
ggtitle("BIKESTORE'S SALES", subtitle = "By vendor partner (Millions U.S$)") +
xlab("Store") +
ylab("Sales (millions)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by store percentages
storeAggs %>%
ggplot(aes(fct_reorder(store_name, storeTotPerc),
storeTotPerc, fill = store_name)) +
geom_col() +
theme_clean() +
geom_text(aes(label = paste(storeTotPerc, "%"), vjust =1)) +
ggtitle("BIKESTORE'S SALES",
subtitle = "By vendor partner percentage volumes") +
xlab("Store") +
ylab("Percentage (%)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by store and category
bikeStores %>%
ggplot(aes(fct_reorder(store_name, grand_sales_totals), grand_sales_totals,
fill = category_name)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By vendor partner and category totals (Millions U.S$)") +
xlab("Category") +
ylab("sales (millions)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)), vjust = 1,
stat = "identity", position_stack()) +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by store and category percentage
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(store_name, perc), perc,
fill = category_name)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By vendor partner and category totals (%s)") +
xlab("Category") +
ylab("sales percentage") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")), vjust = 1,
stat = "identity", position_stack()) +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by city asc
head(cityAggs)
## # A tibble: 3 x 5
## city cityTot cityAvg `n()` cityTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Rowlett 6.85 0.979 7 34.6
## 2 Baldwin 6.48 0.926 7 32.7
## 3 Santa Cruz 6.48 0.926 7 32.7
cityAggs %>%
ggplot(aes(fct_reorder(city, cityTot), cityTot, fill = city)) +
geom_col() +
theme_clean() +
geom_text(aes(label = paste("$", cityTot), vjust = 1)) +
xlab("City") +
ylab("Sales (millions)") +
ggtitle("BIKESTORE'S SALES", subtitle = "By city totals (Millions U.S$)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by city desc
head(cityAggs)
## # A tibble: 3 x 5
## city cityTot cityAvg `n()` cityTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 Rowlett 6.85 0.979 7 34.6
## 2 Baldwin 6.48 0.926 7 32.7
## 3 Santa Cruz 6.48 0.926 7 32.7
cityAggs %>%
ggplot(aes(fct_reorder(city, - cityTot), cityTot, fill = city)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES PROJECTIONS", subtitle = "By city totals (Millions U.S$)") +
geom_text(aes(label = paste("$", cityTot), vjust = 1)) +
xlab("City") +
ylab("Sales (millions)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by city and category
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(city, grand_sales_totals), grand_sales_totals,
fill = category_name)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By city and category totals (Millions U.S$)") +
xlab("City") +
ylab("sales (millions)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)), vjust = 1,
stat = "identity", position_stack()) +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by city and category percentage
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(city, perc), perc, fill = category_name)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By city and category totals (%s)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")), vjust = 1,
stat = "identity", position_stack()) +
xlab("City") +
ylab("Percentages (%)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))

#Totals by city and store asc
head(stateAggs)
## # A tibble: 3 x 5
## state stateTot stateAvg `n()` stateTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 TX 6.85 0.979 7 34.6
## 2 CA 6.48 0.926 7 32.7
## 3 NY 6.48 0.926 7 32.7
stateAggs %>%
ggplot(aes(fct_reorder(state, stateTot), stateTot, fill = state)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By state (Millions U.S$)") +
geom_text(aes(label = paste("$", stateTot), vjust = 1)) +
xlab("State") +
ylab("Sales (millions)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by city desc
head(stateAggs)
## # A tibble: 3 x 5
## state stateTot stateAvg `n()` stateTotPerc
## <chr> <dbl> <dbl> <int> <dbl>
## 1 TX 6.85 0.979 7 34.6
## 2 CA 6.48 0.926 7 32.7
## 3 NY 6.48 0.926 7 32.7
stateAggs %>%
ggplot(aes(fct_reorder(state, - stateTot), stateTot, fill = state)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By state (Millions U.S$)") +
geom_text(aes(label = paste("$", stateTot), vjust = 1)) +
xlab("State") +
ylab("Sales (millions)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by state and category
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(state, grand_sales_totals), grand_sales_totals,
fill = category_name)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By state and category totals (Millions U.S$)") +
xlab("State") +
ylab("sales (millions)") +
geom_text(bikeStores, mapping = aes(label = paste("$", grand_sales_totals)), vjust = 1,
stat = "identity", position_stack()) +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5)) +
scale_y_continuous(labels = scales::dollar_format())

#Totals by state and category percentage
head(bikeStores)
## category_name store_name city state grand_sales_totals perc
## 1 Road Bikes Baldwin Bikes Baldwin NY 2.48 12.49
## 2 Road Bikes Rowlett Bikes Rowlett TX 2.20 11.12
## 3 Road Bikes Santa Cruz Bikes Santa Cruz CA 2.14 10.82
## 4 Mountain Bikes Rowlett Bikes Rowlett TX 1.48 7.48
## 5 Electric Bikes Rowlett Bikes Rowlett TX 1.39 7.02
## 6 Mountain Bikes Santa Cruz Bikes Santa Cruz CA 1.39 7.00
bikeStores %>%
ggplot(aes(fct_reorder(state, perc), perc, fill = category_name)) +
geom_col() +
theme_clean() +
ggtitle("BIKESTORE'S SALES", subtitle = "By state and category totals (%s)") +
geom_text(bikeStores, mapping = aes(label = paste(perc, "%")), vjust = 1,
stat = "identity", position_stack()) +
xlab("State") +
ylab("Percentages (%)") +
theme(axis.text.x = element_text(face = "bold")) +
theme(axis.text.y = element_text(face = "bold")) +
theme(axis.title.x = element_text(face = "bold")) +
theme(axis.title.y = element_text(face = "bold")) +
theme(plot.title = element_text(hjust = .5)) +
theme(plot.subtitle = element_text(hjust = .5))
