Explanatory visuals, part 2: Focusing attention
- sam33frodon
- Aug 25, 2021
- 13 min read
Updated: Aug 31, 2021
Note: All of the following graphs were created using ggplot2 and are inspired from the book Storytelling With Data: Let’s Practice!
(Ref: Knaflic, Cole. Storytelling With Data: Let’s Practice! Wiley, © 2019.)
The author created all the figures using Excel and PowerPoint.
In this post, I will use mainly two ubiquitous packages, namely ggplot2 (for data visualization) and tidyverse (for data transforming).
Case study : Year-over-year change (“YoY,” measured as percent change in dollar sales volume) for cat food brands from a pet food manufacturer.
Data preparation can be found here (R code)
1. To emphasize the Feline line of brands

Figure 1. Focus on Feline brand line (R code)
2. To draw attention to the brands that had decreases in year-over-year sales

Figure 2. Focus on decreasing brands (R code)
3. To draw attention to brands having increasing sales

Figure 3. Focus on increasing brands (R code)
4. Two comprehensive slides


Coding
Data preparation
library(ggplot2)
library(tidyverse)
library(stringr)
library(ggtext)
brand <- c("Fran's Recipe","Wholesome Goodness","Lifestyle","Coat Protection","Diet Lifestyle",
"Feline Basics","Lifestyle Plus","Feline Freedom","Feline Gold","Feline Platinum",
"Feline Instinct","Feline Pro","Farm Fresh Tasties","Feline Royal","Feline Focus",
"Feline Grain Free","Feline Silver","NutriBalance","Farm Fresh Basics")
change <- c(-14,-13,-10,-9,-8,-5,-4,-2,1,1,2,3,4,5,9,9,12,16,17)
data <- data.frame(brand,change)
data$brand <- as.factor(data$brand)
data
## brand change
## 1 Fran's Recipe -14
## 2 Wholesome Goodness -13
## 3 Lifestyle -10
## 4 Coat Protection -9
## 5 Diet Lifestyle -8
## 6 Feline Basics -5
## 7 Lifestyle Plus -4
## 8 Feline Freedom -2
## 9 Feline Gold 1
## 10 Feline Platinum 1
## 11 Feline Instinct 2
## 12 Feline Pro 3
## 13 Farm Fresh Tasties 4
## 14 Feline Royal 5
## 15 Feline Focus 9
## 16 Feline Grain Free 9
## 17 Feline Silver 12
## 18 NutriBalance 16
## 19 Farm Fresh Basics 17
theme_ex1 <- theme(plot.title = element_markdown(size=18),
plot.subtitle = element_markdown(size=12,face="bold", color="#777B7E"),
axis.title.y = element_blank(), # weird, why y here ?
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_markdown(hjust = 0.49),
axis.text.x = element_text(color ="#777B7E", face="bold"),
axis.line.x = element_line(color="grey", size = 1),
axis.ticks.x = element_line(color="#a9a9a9"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
Code for figure 1
ggplot(data = data,aes (x= reorder(brand, -change), y = change))+
geom_bar(stat= "identity") +
geom_bar(data = data %>% filter(str_detect(brand, "Feline")) , stat = "identity", fill ="#570861")+
annotate("text",x = 19.1, y = 1, label= "Fran's Recipe",hjust = 0, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 18.1, y = 1, label= "Wholesome Goodness",hjust = 0, color = "#777B7E",fontface = 1.5)+
annotate("text",x = 17.1, y = 1, label= "Lifestyle", hjust = 0, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 16.1, y = 1, label= "Coat Protection", hjust = 0, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 15.1, y = 1, label= "Diet Lifestyle", hjust = 0, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 14.1, y = 1, label= "Feline Basic", hjust = 0, color = "#570861",fontface = 2) +
annotate("text",x = 13.1, y = 1, label= "Lifestyle Plus", hjust = 0, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 12.1, y = 1, label= "Feline Fredom", hjust = 0, color = "#570861", fontface = 2) +
annotate("text",x = 11.1, y = -1, label= "Feline Platinum",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 10.1, y = -1, label= "Feline Gold",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 9.1, y = -1, label= "Feline Instinct", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 8.1, y = -1, label= "Feline Pro", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 7.1, y = -1, label= "Farm Fresh Tasties", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 6.1, y = -1, label= "Feline Royal", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 5.1, y = -1, label= "Feline Grain Free", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 4.1, y = -1, label= "Feline Focus",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 3.1, y = -1, label= "Feline Silver", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 2.1, y = -1, label= "Nutri Balance", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 1.1, y = -1, label= "Farm Fresh Basic", hjust = 1, color = "#777B7E",fontface = 1.5) +
labs(title = "Cat food brands: <span style = 'color: #570861;'>**most in Feline line increased**</span>",
subtitle = "YEAR-OVER-YEAR % CHANGE IN SALE VOLUME($)\n") +
scale_y_continuous(name = "DECREASED | INCREASED",
limits = c(-20, 20),
breaks = seq(-20, 20, by = 5),
labels = function(x) paste0(x,"%"),
position = 'right') +
theme_ex1 +
coord_flip()
Code for figure 2
ggplot(data = data,aes (x= reorder(brand, -change), y = change))+
geom_bar(stat= "identity") +
geom_bar(data = data %>% filter(change < 0) , stat = "identity", fill ="#FF4500")+
annotate("text",x = 19.1, y = 1, label= "Fran's Recipe",hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 18.1, y = 1, label= "Wholesome Goodness",hjust = 0, color = "#FF4500",fontface = 2)+
annotate("text",x = 17.1, y = 1, label= "Lifestyle", hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 16.1, y = 1, label= "Coat Protection", hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 15.1, y = 1, label= "Diet Lifestyle", hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 14.1, y = 1, label= "Feline Basic", hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 13.1, y = 1, label= "Lifestyle Plus", hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 12.1, y = 1, label= "Feline Fredom", hjust = 0, color = "#FF4500", fontface = 2) +
annotate("text",x = 11.1, y = -1, label= "Feline Platinum",hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 10.1, y = -1, label= "Feline Gold",hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 9.1, y = -1, label= "Feline Instinct", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 8.1, y = -1, label= "Feline Pro", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 7.1, y = -1, label= "Farm Fresh Tasties", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 6.1, y = -1, label= "Feline Royal", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 5.1, y = -1, label= "Feline Grain Free", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 4.1, y = -1, label= "Feline Focus",hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 3.1, y = -1, label= "Feline Silver", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 2.1, y = -1, label= "Nutri Balance", hjust = 1, color = "#777B7E",fontface = 1.5) +
annotate("text",x = 1.1, y = -1, label= "Farm Fresh Basic", hjust = 1, color = "#777B7E",fontface = 1.5) +
labs(title = "Cat food brands: <span style='color:#FF4500;'>**8 brands decreased in sale**</span>",
subtitle = "YEAR-OVER-YEAR % CHANGE IN SALE VOLUME ($)<br>",
y = "DECREASED | INCREASED") +
scale_y_continuous(limits = c(-20, 20),
breaks = seq(-20, 20, by = 5),
labels = function(x) paste0(x,"%"),
#labels =seq(-20, 20, by = 5),
position = 'right') + # we flipped axes
coord_flip() +
theme_ex1
Code for figure 3
ggplot(data = data,aes (x= reorder(brand, -change), y = change))+
geom_bar(stat= "identity") +
geom_bar(data = data %>% filter(change > 0), stat = "identity", fill ="#2B547E")+
annotate("text",x = 19.1, y = 1, label= "Fran's Recipe",hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 18.1, y = 1, label= "Wholesome Goodness",hjust = 0, color = "#777B7E",fontface = 2)+
annotate("text",x = 17.1, y = 1, label= "Lifestyle", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 16.1, y = 1, label= "Coat Protection", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 15.1, y = 1, label= "Diet Lifestyle", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 14.1, y = 1, label= "Feline Basic", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 13.1, y = 1, label= "Lifestyle Plus", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 12.1, y = 1, label= "Feline Fredom", hjust = 0, color = "#777B7E", fontface = 2) +
annotate("text",x = 11.1, y = -1, label= "Feline Platinum",hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 10.1, y = -1, label= "Feline Gold",hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 9.1, y = -1, label= "Feline Instinct", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 8.1, y = -1, label= "Feline Pro", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 7.1, y = -1, label= "Farm Fresh Tasties", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 6.1, y = -1, label= "Feline Royal", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 5.1, y = -1, label= "Feline Grain Free", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 4.1, y = -1, label= "Feline Focus",hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 3.1, y = -1, label= "Feline Silver", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 2.1, y = -1, label= "Nutri Balance", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 1.1, y = -1, label= "Farm Fresh Basic", hjust = 1, color = "#2B547E",fontface = 2) +
labs(title = "Cat food brands: <span style = 'color:#2B547E;'>**11 brands flat to increasing**</span>",
subtitle = "YEAR-OVER-YEAR % CHANGE IN SALE VOLUME($)\n",
y = "DECREASED | INCREASED") +
scale_y_continuous(limits = c(-20, 20),
breaks = seq(-20, 20, by = 5),
#labels =seq(-20, 20, by = 5),
position = 'right') + # we flipped axes
coord_flip() +
theme_ex1
Code for figure 4a
ggplot(data = data,aes (x= reorder(brand, -change), y = change))+
geom_bar(stat= "identity", fill ="darkgrey") +
geom_bar(data = data %>% filter(str_detect(brand, "Feline")), stat = "identity", fill ="#570861") +
geom_bar(data = data %>%filter(str_detect(brand, "Lifestyle")), stat = "identity", fill ="black") +
annotate("text",x = 19.1, y = 1, label= "Fran's Recipe",hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 18.1, y = 1, label= "Wholesome Goodness",hjust = 0, color = "#777B7E",fontface = 2)+
annotate("text",x = 17.1, y = 1, label= "Lifestyle", hjust = 0, color = "black",fontface = 2) +
annotate("text",x = 16.1, y = 1, label= "Coat Protection", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 15.1, y = 1, label= "Diet Lifestyle", hjust = 0, color = "black",fontface = 2) +
annotate("text",x = 14.1, y = 1, label= "Feline Basic", hjust = 0, color = "#570861",fontface = 2) +
annotate("text",x = 13.1, y = 1, label= "Lifestyle Plus", hjust = 0, color = "black",fontface = 2) +
annotate("text",x = 12.1, y = 1, label= "Feline Fredom", hjust = 0, color = "#570861", fontface = 2) +
annotate("text",x = 11.1, y = -1, label= "Feline Platinum",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 10.1, y = -1, label= "Feline Gold",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 9.1, y = -1, label= "Feline Instinct", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 8.1, y = -1, label= "Feline Pro", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 7.1, y = -1, label= "Farm Fresh Tasties", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 6.1, y = -1, label= "Feline Royal", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 5.1, y = -1, label= "Feline Grain Free", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 4.1, y = -1, label= "Feline Focus",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 3.1, y = -1, label= "Feline Silver", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 2.1, y = -1, label= "Nutri Balance", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 1.1, y = -1, label= "Farm Fresh Basic", hjust = 1, color = "#777B7E",fontface = 2) +
labs(title = "Cat food brands: **Mixed results in sales year-over-year**",
subtitle = "YEAR-OVER-YEAR % CHANGE IN SALE VOLUME($)\n",
y = "DECREASED | INCREASED") +
scale_y_continuous(limits = c(-20, 20),
breaks = seq(-20, 20, by = 5),
#labels =seq(-20, 20, by = 5),
position = 'right') + # we flipped axes
coord_flip() +
theme_ex1
library("gridExtra")
p1 <- ggplot(data = data,aes (x= reorder(brand, -change), y = change))+
geom_bar(stat= "identity", fill ="darkgrey") +
geom_bar(data = data %>% filter(str_detect(brand, "Feline")), stat = "identity", fill ="#570861") +
geom_bar(data = data %>%filter(str_detect(brand, "Lifestyle")), stat = "identity", fill ="black") +
annotate("text",x = 19.1, y = 1, label= "Fran's Recipe",hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 18.1, y = 1, label= "Wholesome Goodness",hjust = 0, color = "#777B7E",fontface = 2)+
annotate("text",x = 17.1, y = 1, label= "Lifestyle", hjust = 0, color = "black",fontface = 2) +
annotate("text",x = 16.1, y = 1, label= "Coat Protection", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 15.1, y = 1, label= "Diet Lifestyle", hjust = 0, color = "black",fontface = 2) +
annotate("text",x = 14.1, y = 1, label= "Feline Basic", hjust = 0, color = "#570861",fontface = 2) +
annotate("text",x = 13.1, y = 1, label= "Lifestyle Plus", hjust = 0, color = "black",fontface = 2) +
annotate("text",x = 12.1, y = 1, label= "Feline Fredom", hjust = 0, color = "#570861", fontface = 2) +
annotate("text",x = 11.1, y = -1, label= "Feline Platinum",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 10.1, y = -1, label= "Feline Gold",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 9.1, y = -1, label= "Feline Instinct", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 8.1, y = -1, label= "Feline Pro", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 7.1, y = -1, label= "Farm Fresh Tasties", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 6.1, y = -1, label= "Feline Royal", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 5.1, y = -1, label= "Feline Grain Free", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 4.1, y = -1, label= "Feline Focus",hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 3.1, y = -1, label= "Feline Silver", hjust = 1, color = "#570861",fontface = 2) +
annotate("text",x = 2.1, y = -1, label= "Nutri Balance", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 1.1, y = -1, label= "Farm Fresh Basic", hjust = 1, color = "#777B7E",fontface = 2) +
labs(title = "Cat food brands: **Mixed results in sales year-over-year**",
subtitle = "YEAR-OVER-YEAR % CHANGE IN SALE VOLUME($)\n",
y = "DECREASED | INCREASED") +
scale_y_continuous(limits = c(-20, 20),
breaks = seq(-20, 20, by = 5),
#labels =seq(-20, 20, by = 5),
position = 'right') + # we flipped axes
coord_flip() +
theme(plot.title = element_markdown(size=18),
plot.subtitle=element_text(size=12, face="bold", color="#777B7E"),
axis.title.y = element_blank(), # weird, why y here ?
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_markdown(hjust = 0.49),
axis.text.x = element_text(color ="#777B7E", face="bold"),
axis.line.x = element_line(color="grey", size = 1),
axis.ticks.x = element_line(color="#a9a9a9"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
df <- tibble(
label = c(
"<span style='color:#000000'>**Brands in the Lifestyle line all<br>
decreased year-over-year**</span>
<span style='color:#000000'>mainly <br>
due to a marketing shift away from<br>
these products. Classic Lifestyle had <br>
the biggest decrease in sales, down <br>
10% year-over-year while Lifestyle <br>
Plus had the smallest decrease (4%).</span>",
"<span style='color:#570861'>**Most brands in the Feline line <br>
increased in sales year-over-year**</span>,<br>
<span style='color:#000000'> largely due to the partnership <br>
with PetFriends retailers that<br>
we entered into mid-year.<br>
We anticipate continued momentum <br>in the coming year.</span>"
),
x = c(0, 0),
y = c(0.6, 0.2),
hjust = c(0, 0),
vjust = c(0.5, 0.5),
color = c("white", "white"), # contour
fill = c("white", "white")
)
p2 <- ggplot(df) +
aes(x, y,
label = label,
color = color,
fill = fill,
hjust = hjust,
vjust = vjust) +
geom_richtext() +
scale_color_identity() +
scale_fill_identity() +
xlim(0, 1) + ylim(0, 1) +
theme(axis.title = element_blank(), # weird, why y here ?
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
grid.arrange(p1, p2,ncol= 2,widths = c(6,3))
Code for figure 4b
hl1 <- data %>%
filter(brand == "Fran's Recipe" | brand == "Wholesome Goodness")
hl2 <- data %>%
filter (brand %in% c("Lifestyle", "Coat Protection", "Diet Lifestyle"))
hl3 <- data %>%
filter(brand %in% c("Feline Focus", "Feline Grain Free", "Feline Silver"))
hl4 <- data %>%
filter(brand == "NutriBalance" | brand == "Farm Fresh Basics")
p3 <- ggplot(data = data, aes (x= reorder(brand, -change), y = change))+
geom_bar(stat= "identity", fill ="darkgrey") +
geom_bar(data = hl1, stat = "identity", fill ="#FF4500") +
geom_bar(data = hl2, stat = "identity", fill ="#ffa280") +
geom_bar(data = hl3, stat = "identity", fill ="#97BAEB") +
geom_bar(data = hl4, stat = "identity", fill ="#2B547E") +
annotate("text",x = 19.1, y = 1, label= "Fran's Recipe",hjust = 0, color = "#FF4500",fontface = 2) +
annotate("text",x = 18.1, y = 1, label= "Wholesome Goodness",hjust = 0, color = "#FF4500",fontface = 2)+
annotate("text",x = 17.1, y = 1, label= "Lifestyle", hjust = 0, color = "#ffa280",fontface = 2) +
annotate("text",x = 16.1, y = 1, label= "Coat Protection", hjust = 0, color = "#ffa280",fontface = 2) +
annotate("text",x = 15.1, y = 1, label= "Diet Lifestyle", hjust = 0, color = "#ffa280",fontface = 2) +
annotate("text",x = 14.1, y = 1, label= "Feline Basic", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 13.1, y = 1, label= "Lifestyle Plus", hjust = 0, color = "#777B7E",fontface = 2) +
annotate("text",x = 12.1, y = 1, label= "Feline Fredom", hjust = 0, color = "#777B7E", fontface = 2) +
annotate("text",x = 11.1, y = -1, label= "Feline Platinum",hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 10.1, y = -1, label= "Feline Gold",hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 9.1, y = -1, label= "Feline Instinct", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 8.1, y = -1, label= "Feline Pro", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 7.1, y = -1, label= "Farm Fresh Tasties", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 6.1, y = -1, label= "Feline Royal", hjust = 1, color = "#777B7E",fontface = 2) +
annotate("text",x = 5.1, y = -1, label= "Feline Grain Free", hjust = 1, color = "#97BAEB",fontface = 2) +
annotate("text",x = 4.1, y = -1, label= "Feline Focus",hjust = 1, color = "#97BAEB",fontface = 2) +
annotate("text",x = 3.1, y = -1, label= "Feline Silver", hjust = 1, color = "#97BAEB",fontface = 2) +
annotate("text",x = 2.1, y = -1, label= "Nutri Balance", hjust = 1, color = "#2B547E",fontface = 2) +
annotate("text",x = 1.1, y = -1, label= "Farm Fresh Basic", hjust = 1, color = "#2B547E",fontface = 2) +
labs(title = "Cat food brands: **Mixed results in sales year-over-year**",
subtitle = "YEAR-OVER-YEAR % CHANGE IN SALE VOLUME($)\n",
y = "DECREASED | INCREASED") +
scale_y_continuous(limits = c(-20, 20),
breaks = seq(-20, 20, by = 5),
#labels =seq(-20, 20, by = 5),
position = 'right') + # we flipped axes
coord_flip() +
theme(plot.title = element_markdown(size=18),
plot.subtitle=element_text(size=12, face="bold", color="#777B7E"),
axis.title.y = element_blank(), # weird, why y here ?
axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.x = element_markdown(hjust = 0.49),
axis.text.x = element_text(color ="#777B7E", face="bold"),
axis.line.x = element_line(color="grey", size = 1),
axis.ticks.x = element_line(color="#a9a9a9"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
df_box <- tibble(
label = c("Eight key cat food brands declined in sales year-over-year, with five brands decreasing 7%+.
This was expected in some cases due to focus shift toward higher margin brands.
<span style='color:#FF4500'>
**Fran's Recipe and Wholesome Goodness
each declined by more than 13%**,
which was more than expected.
</span>",
"On the positive side, <span style='color:#2B547E'> five brands increased 8%+ year-over-year,
with **marked 16%+ increases for NutriBalance and Farm Fresh Basics**.
</span>",
"**What can we learn from increasing brands that we can apply elsewhere?** Let's discuss next steps."),
x = c(0, 0, 0),
y = c(0.6, 0.3, 0.1),
color = c("white", "white","white"),
fill = c("white", "white","white")
)
p4 <- ggplot() +
geom_textbox(data = df_box,
aes(x,y, label = label),
box.color = "white", fill = "white",
hjust = 0,
# box.r = unit(10, "pt"),
width = unit(200, "pt"),
box.padding = unit(c(0, 0, 0, 0), "pt")) +
scale_color_identity() +
scale_fill_identity() +
xlim(0, 1) + ylim(0, 1) +
theme(axis.title = element_blank(), # weird, why y here ?
axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank())
grid.arrange(p3, p4,ncol= 2,widths = c(6,3))
Comments