Data Construction
df <- tibble(
person = c( rep('Rich P.',2) , rep('Buddy B.',2)
, rep('Terencio K.',2) , rep('Wilfred M.',2)
, rep('Tish L.',2) , rep('Reggie K.',2)
, rep('Beverley P.',2) , rep('Khalil E.',2)
, rep('Sunil C.',2) , rep('Elihi L.',2)
, rep('Derrick M.',2) , rep('Deerdre F.',2)
, rep('Mariana G.',2) , rep('Kirsti F.',2)
, rep('Robinette D.',2) , rep('Abbot L.',2)
, rep('Allyson S.',2) , rep('Viola K.',2)
, rep('Dagma M.',2) , rep('Teemu S.',2)
, rep('Sid H.',2) , rep('Rocky D.',2)
, rep('Dannie L.',2) , rep('Worthy D.',2)
, rep('Miguel C.',2)
)
, status = rep(c('Revenue_target','closed_deal'), 25)
, value = c( 75000, 63200, 73200, 68000, 72400, 54000
, 71800, 55400, 69200, 56800, 67800, 68000, 65800
, 44600, 64400, 38400, 62600, 39800, 61400, 62400
, 58600, 55200, 57200, 39000, 57000, 42600, 56800
, 49200, 54600, 39800, 53600, 61300, 53200, 58400
, 50800, 52800, 50600, 45000, 48600, 53600, 46600
, 41200, 45400, 52800, 45200, 28000, 43600, 47000
, 43600, 39200
)
)
Plot Construction
# Base plot
ggplot(df)+
geom_bar(aes(x = person, y = value, fill = status), stat = 'identity')+
theme_minimal()

# Flip Coord
ggplot(df)+
geom_bar(aes(x = person, y = value, fill = status), stat = 'identity')+
coord_flip()+
theme_minimal()

# Separate Revenue Target and Closed Deal
ggplot()+
geom_bar(
data = df %>% filter(status == 'Revenue_target')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
)+
geom_bar(
data = df %>% filter(status == 'closed_deal')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'slateblue'
)+
coord_flip()+
theme_minimal()

# Color Selection
# Revenue Target White with Black Border
# Closed Deal steelblue
ggplot()+
geom_bar(
data = df %>% filter(status == 'Revenue_target')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'white'
, color = 'black'
)+
geom_bar(
data = df %>% filter(status == 'closed_deal')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
)+
coord_flip()+
theme_minimal()

# Order by Revenue Target
ggplot()+
geom_bar(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value)
, stat = 'identity'
, fill = 'white'
, color = 'black'
)+
geom_bar(
data = df %>% filter(status == 'closed_deal')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
)+
scale_y_continuous(position = "right")+
xlab('')+ylab('')+
coord_flip()+
theme_minimal()

# Add Texts
ggplot()+
geom_bar(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value)
, stat = 'identity'
, fill = 'white'
, color = 'black'
)+
geom_text(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value, label = paste(value/1000, 'K'))
, nudge_y = -2500, fontface = 'bold')+
geom_bar(
data = df %>% filter(status == 'closed_deal')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
)+
geom_text(
data = df %>% filter(status == 'closed_deal')
, aes(x = reorder(person, value), y = value, label = paste(value/1000, 'K'))
, nudge_y = -2500, color = 'white', fontface = 'bold')+
scale_y_continuous(position = "right")+
xlab('')+ylab('')+
coord_flip()+
theme_minimal()

# Add Title and subtitle
ggplot()+
geom_bar(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value)
, stat = 'identity'
, fill = 'white'
, color = 'black'
)+
geom_text(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value, label = paste(value/1000, 'K'))
, nudge_y = -2500, fontface = 'bold')+
geom_bar(
data = df %>% filter(status == 'closed_deal')
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
)+
geom_text(
data = df %>% filter(status == 'closed_deal')
, aes(x = reorder(person, value), y = value, label = paste(value/1000, 'K'))
, nudge_y = -2500, color = 'white', fontface = 'bold')+
scale_y_continuous(position = "right")+
xlab('')+ylab('')+
coord_flip()+
theme_minimal()+
plot_annotation(
title = 'Revenue report for Q2 Revenue Targets vs. Closed deals by associate'
, theme = theme(plot.title = element_text(hjust = 0.5))
)

# Change alpha if closed_deal < Revenue_target
df_flag <- df %>%
pivot_wider(names_from = status, values_from = value) %>%
mutate(
flag = ifelse(closed_deal < Revenue_target, .5, 1)
) %>% dplyr::select(person, flag)
df <- inner_join(df, df_flag, by = 'person')
ggplot()+
geom_bar(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value)
, stat = 'identity'
, fill = 'white'
, color = 'black'
)+
geom_text(
data = df %>% filter(status == 'Revenue_target')
, aes(x = reorder(person, value), y = value, label = paste(value/1000, 'K'))
, nudge_y = -2500, fontface = 'bold')+
geom_bar(
data = df %>% filter(status == 'closed_deal') %>% filter(flag != 1)
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
, alpha = .5
)+
geom_bar(
data = df %>% filter(status == 'closed_deal') %>% filter(flag == 1)
, aes(x = person, y = value)
, stat = 'identity'
, fill = 'steelblue'
)+
geom_text(
data = df %>% filter(status == 'closed_deal')
, aes(x = reorder(person, value), y = value, label = paste(value/1000, 'K'))
, nudge_y = -3000, color = 'white', fontface = 'bold')+
scale_y_continuous(position = "right", labels = unit_format(unit = "k", scale = 1e-3))+
labs(
title = "Sales report for Q2 **revenue targets** vs <span style='color:#4682B4'>closed deals</span> by associate"
)+
xlab('')+ylab('')+
coord_flip()+
theme_minimal()+
theme(
plot.title = element_markdown(lineheight = 1.1),
legend.text = element_markdown(size = 11),
plot.caption = element_markdown(size = 11)
)
