NOTE: no single right approach for visualizing data

meals <- c(40139,127020,168193,153115,202102,232897,277912,205350,233389,232797)
year <- c(2010:2019)
df <- data.frame(year, meals)
library(ggplot2)
ggplot(data=df, 
       aes(x=year, 
           y=meals)) +
  geom_bar(stat="identity", fill="steelblue", width = 0.75) +
  scale_x_continuous(name = "Campaign year",breaks=seq(2010, 2019,1)) +
  scale_y_continuous(breaks=seq(0, 300000, 50000),
                     labels = function(x) format(x, scientific = FALSE)) +
  ggtitle("Meals served over time") +
  ylab("# of meals served") +
  theme(plot.title = element_text(size=16),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank())

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.5     v dplyr   1.0.3
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.0
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(ggrepel)
## Warning: package 'ggrepel' was built under R version 4.0.5
highlight_df <- df %>% 
  filter(year %in% c(2010, 2013, 2016, 2019))

ggplot(data=df, aes(x=year, 
                    y=meals)) +
  geom_line(color="steelblue", size = 1.5) +
  geom_point(data = highlight_df, 
             aes(x = year,y = meals), 
             color = "steelblue",
             size=5) +
  geom_text(data = highlight_df,
            aes(x = year,y = meals,label = meals, size = 12),
            color = "blue",
            nudge_x = 0.7,
            nudge_y = 0,
            show.legend =F) +
  scale_x_continuous(name = "Campaign year",breaks=seq(2010, 2019,1)) +  
  scale_y_continuous(breaks=seq(0, 310000, 50000),
                     labels = function(x) format(x, scientific = FALSE)) +
  ggtitle("Meals served over time") +
  ylab("# of meals served") +
  theme(plot.title = element_text(size=16),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.ticks = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank())

capacity and demand measured in number of project hours over time. It is currently graphed as a horizontal bar chart. But is this the only way to show this data? Certainly not!

project <- read_csv("project.csv")
## 
## -- Column specification --------------------------------------------------------
## cols(
##   DATE = col_character(),
##   CAPACITY = col_number(),
##   DEMAND = col_number()
## )
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
project$DATE2 <-ym(project$DATE)

Now we are ready to tidy our data and convert the table to long format. To do this we will use the gather function from the tidyr package.

df <- gather(project, category, project, DEMAND:CAPACITY)
df$category = factor(df$category, levels = c("DEMAND", "CAPACITY"), ordered = TRUE)
df
## # A tibble: 18 x 4
##    DATE   DATE2      category project
##    <chr>  <date>     <ord>      <dbl>
##  1 19-Apr 2019-04-01 DEMAND     46193
##  2 19-May 2019-05-01 DEMAND     49131
##  3 19-Jun 2019-06-01 DEMAND     50124
##  4 19-Jul 2019-07-01 DEMAND     48850
##  5 19-Aug 2019-08-01 DEMAND     47602
##  6 19-Sep 2019-09-01 DEMAND     43697
##  7 19-Oct 2019-10-01 DEMAND     41058
##  8 19-Nov 2019-11-01 DEMAND     37364
##  9 19-Dec 2019-12-01 DEMAND     34364
## 10 19-Apr 2019-04-01 CAPACITY   29263
## 11 19-May 2019-05-01 CAPACITY   28037
## 12 19-Jun 2019-06-01 CAPACITY   21596
## 13 19-Jul 2019-07-01 CAPACITY   25895
## 14 19-Aug 2019-08-01 CAPACITY   25813
## 15 19-Sep 2019-09-01 CAPACITY   22427
## 16 19-Oct 2019-10-01 CAPACITY   23605
## 17 19-Nov 2019-11-01 CAPACITY   24263
## 18 19-Dec 2019-12-01 CAPACITY   24243

Basic bars

ggplot(df, aes(x = DATE2, 
               y = project, 
               fill = category)) +
  geom_bar(stat = "identity", 
           position = 'dodge', 
           color="#1974D2",
           size =1.2) +
  
  scale_fill_manual(values = c("white", "#1974D2")) +
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2020-03-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  ggtitle("Demande vs Capacity over time") +
  labs(subtitle = bquote("DAMANDE|"~ bold("CAPACITY") )) +
  ylab("Number of project hours") +
  
  theme(plot.title = element_text(size=16),
        plot.subtitle = element_text(color = "#1974D2"),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.ticks = element_blank(),
        axis.title.x=element_blank(),
        axis.line = element_line(color="grey", size = 1),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank())

ggplot(df, aes(x = DATE2, 
               y = project)) +
  geom_line(data = filter(df, category == "DEMAND"), size = 0.5, color =  "#1974D2") +  # bright navy blue
  geom_line(data = filter(df, category == "CAPACITY"), size = 1.5, color =  "#1974D2") +
  
  annotate("text", x = as.Date("2019-12-10"), y = 34360, label = "34K", color = "#1974D2") + # as.Date is required
  annotate("text", x = as.Date("2020-01-10"), y = 34360, label = "DEMAND", color = "#1974D2") + # as.Date is required
  annotate("text", x = as.Date("2019-12-10"), y = 24360, label = "24K", color = "#1974D2", fontface = "bold") +
  annotate("text", x = as.Date("2020-01-10"), y = 24360, label = "CAPACITY", color = "#1974D2", fontface = "bold") +
  
  expand_limits(x = as.Date(c("2019-04-01", "2020-01-15"))) +

  
  scale_y_continuous(limits = c(0, 60000), breaks = seq(0, 60000, by = 10000)) +
  
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2019-12-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  
  ggtitle("Demande vs Capacity over time") +
  labs(subtitle = bquote("DAMAND |"~ bold("CAPACITY") )) +
  ylab("Number of project hours") +
  
  theme(plot.title = element_text(size=16),
        plot.subtitle = element_text(color = "#1974D2"),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.title.x=element_blank(),
        axis.line = element_line(color="grey", size = 1),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1.25,1.25,1.2),"cm")) # to change the margin top, right. bottom. left

Overlapping bars

ggplot(df, aes(x = DATE2, 
               y = project)) +
  geom_bar(data = filter(df, category == "DEMAND"), stat = "identity", width = 14, color =  "#1974D2", fill = "white") +  # bright navy blue
  geom_bar(data = filter(df, category == "CAPACITY"), stat = "identity", width = 20, color =  "#1974D2", fill = "#1974D2") +
  
  scale_y_continuous(limits = c(0, 60000), breaks = seq(0, 60000, by = 10000)) +
  
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2019-12-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  
  ggtitle("Demande vs Capacity over time") +
  labs(subtitle = bquote("DEMAND |"~ bold("CAPACITY") )) +
  ylab("Number of project hours") +
  
  theme(plot.title = element_text(size=18),
        plot.subtitle = element_text(color = "#1974D2", size=14),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.title.x=element_blank(),
        axis.line = element_line(color="grey", size = 1),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1.25,1.25,1.2),"cm")) # to change the margin top, right. bottom. left

ggplot(df, aes(x = DATE2, 
               y = project)) +
  geom_bar(data = filter(df, category == "DEMAND"), stat = "identity", width = 12, color =  "#1974D2", fill = "white", size= 1) +  # bright navy blue
  geom_bar(data = filter(df, category == "CAPACITY"), stat = "identity", width = 20, color =  "#1974D2", fill = "#1974D2", alpha = 0.65) +
  
  scale_y_continuous(limits = c(0, 60000), breaks = seq(0, 60000, by = 10000)) +
  
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2019-12-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  
  ggtitle("Demande vs Capacity over time") +
  labs(subtitle = bquote("DEMAND |"~ bold("CAPACITY") )) +
  ylab("Number of project hours") +
  
  theme(plot.title = element_text(size=18),
        plot.subtitle = element_text(color = "#1974D2", size=14),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.title.x=element_blank(),
        axis.line = element_line(color="grey", size = 1),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1.25,1.25,1.2),"cm")) # to change the margin top, right. bottom. left

Stacked bars

ggplot(df, aes(x = DATE2, 
               y = project)) +
  geom_bar(data = filter(df, category == "DEMAND"), stat = "identity", width = 20, color =  "#1974D2", fill = "#1974D2") +  # bright navy blue
  geom_bar(data = filter(df, category == "CAPACITY"), stat = "identity", width = 20, color =  "#1974D2", fill = "lightgrey") +
  
  scale_y_continuous(limits = c(0, 60000), breaks = seq(0, 60000, by = 10000)) +
  
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2019-12-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  
  ggtitle("Demande vs Capacity over time") +
  labs(subtitle = bquote("CAPACITY |"~ bold("UNMET DEMAND") )) +
  ylab("Number of project hours") +
  
  theme(plot.title = element_text(size=18),
        plot.subtitle = element_text(color = "#1974D2", size=14),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.title.x=element_blank(),
        axis.line = element_line(color="grey", size = 1),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1.25,1.25,1.2),"cm")) # to change the margin top, right. bottom. left

changer the color od subtitle CAPACITY

Dot plot

ggplot(df, aes(x = DATE2, 
               y = project)) +
  geom_point(data = filter(df, category == "DEMAND"), size = 12 , color =  "#1974D2",shape=21) +  # bright navy blue
  geom_point(data = filter(df, category == "CAPACITY"), size =12, color =  "#1974D2") +
  
  scale_y_continuous(limits = c(0, 60000), breaks = seq(0, 60000, by = 10000)) +
  
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2019-12-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  
  ggtitle("Demande vs Capacity over time") +

  ylab("Number of project hours") +
  
  theme(plot.title = element_text(size=18),
        plot.subtitle = element_text(color = "#1974D2", size=14),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.title.x=element_blank(),
        axis.line = element_line(color="grey", size = 1),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1.25,1.25,1.2),"cm")) # to change the margin top, right. bottom. left

ggplot(df, aes(own, method)) + geom_point(aes(colour=factor(label), fill = factor(label)), shape=21, size = 4) + scale_fill_manual(values=c(“blue”, “cyan4”)) + scale_colour_manual(values=c(“white”, “black”))

ggplot(df, aes(x = DATE2, 
               y = project)) +

  geom_bar(data = filter(df, category == "DEMAND"), stat = "identity", width = 17.8, color =  "white", fill = "#1974D2",alpha = 0.4) +  
  geom_bar(data = filter(df, category == "CAPACITY"), stat = "identity", width = 17, color =  "white", fill = "white") +

  geom_point(aes(color = factor(category),fill = factor(category)), 
             shape=21, size = 14, stroke = 2.2) + 
  scale_fill_manual(values=c("white", "#1974D2")) + 
  scale_colour_manual(values=c("steelblue", "#1974D2"))   +
  geom_text(data = filter(df, category == "DEMAND"),
            aes(x = DATE2,y = project,label = round(project/1000,0), size = 10),
            color = "blue",
            show.legend =F) +
  geom_text(data = filter(df, category == "CAPACITY"),
            aes(x = DATE2,y = project,label = round(project/1000,0), size = 10),
            color = "white",
            show.legend =F) +
  
  

  annotate("text", x = as.Date("2019-12-30"), y = 34360, label = "DEMAND", color = "steelblue") + # as.Date is required
  annotate("text", x = as.Date("2019-12-30"), y = 24360, label = "CAPACITY", color = "#1974D2", fontface = "bold") +
  expand_limits(x = as.Date(c("2019-04-01", "2020-01-15"))) +
  
  scale_y_continuous(limits = c(0, 55000), breaks = seq(0, 55000, by = 10000)) + # si non, l echelle de y ne marche pas
  
  scale_x_date(breaks = seq(as.Date("2019-04-01"),
                            as.Date("2019-12-01"),
                            by = "1 month"),
               date_labels = "%b-%y") +
  
  ggtitle("Demande vs Capacity over time") +

  ylab("Number of project hours \n (thousands)") +
  
  theme(plot.title = element_text(size=18),
        plot.subtitle = element_text(color = "#1974D2", size=14),
        axis.text=element_text(size=12),
        axis.title=element_text(size=12),
        axis.line.x= element_line(color="grey", size = 1),
        axis.title.x=element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.ticks.x = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1.25,1.25,1.2),"cm")) # to change the margin top, right. bottom. left

Graph the difference.

My final view is a simple line graph that plots the Unmet Demand (Demand minus Capacity). This is my least favorite of all (or maybe I’d rate it as tied for last with the basic bars), as it feels like too much context is omitted when we go from the two data series to plotting the difference. See Figure 2.4f.

library(ggplot2)
year <- c(2010:2019)
rate <- c(9.7, 2.0, 1.0, 7.0, 15.1, 5.6, 12.3, 4.5, 8.2, 9.1)
attrition <- data.frame(year, rate)
attrition
##    year rate
## 1  2010  9.7
## 2  2011  2.0
## 3  2012  1.0
## 4  2013  7.0
## 5  2014 15.1
## 6  2015  5.6
## 7  2016 12.3
## 8  2017  4.5
## 9  2018  8.2
## 10 2019  9.1
ggplot(data = attrition, 
       aes(x = year, y = rate))+
  geom_point(color = "#1974D2", size = 5) +
# annotation
  annotate("segment", x = 2010, xend = 2019, 
           y = mean(rate), yend = mean(rate), 
           color = "royalblue",linetype="dashed")  + # to control the length of the line
  annotate("text", x = 2011,  y = 8.0, label = "AVERAGE: 7.5%", color = "#1974D2") + 
  scale_x_continuous( n.breaks = 9) + # this is a good w and simple way to generate breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(0, 16), n.breaks = 9) + 

# title
  ggtitle("Attrition rate over time") +

  ylab("Attrition rate (%)") +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x = element_blank(),
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

highlight_df <- attrition %>% 
  filter(year == 2019)

ggplot(data=attrition , aes(x=year, y=rate)) +
  geom_line(color="royalblue", size = 1.2) +
  geom_point(data = highlight_df, 
             aes(x = year,y = rate), 
             color = "royalblue",size=4) +
 

  annotate("segment", x = 2010, xend = 2019, y = mean(rate), yend = mean(rate), color = "royalblue",linetype="dashed") +

  annotate("text", x =2018.5,  y = 6.25, label = "AVG: 7.5%", color = "royalblue") + 
  annotate("text", x = 2019,  y = 10.5, label = "9.1%", color = "royalblue") + 
  scale_x_continuous(expand = c(0, 0),limits = c(2010, 2019.5),  n.breaks = 9) + # this is a good w and simple way to generat breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(0, 16), n.breaks = 9) + 


  ggtitle("Attrition rate over time") +

  ylab("Attrition rate (%)") +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x=element_blank(), # remove year
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

MY IDEA is to combine two graphs

ggplot(data = attrition, 
       aes(x = year, y = rate))+
  
  geom_line(color="royalblue", size = 0.5) +
  geom_point(color = "#1974D2", size = 5) +
# annotation
  annotate("segment", x = 2010, xend = 2019, 
           y = mean(rate), yend = mean(rate), 
           color = "royalblue",linetype="dashed")  + # to control the length of the line
  annotate("text", x = 2011.5,  y = 8.0, label = "AVERAGE: 7.5%", color = "#1974D2") + 
  scale_x_continuous( n.breaks = 9) + # this is a good w and simple way to generate breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(0, 16), n.breaks = 9) + 

# title
  ggtitle("Attrition rate over time") +

  ylab("Attrition rate (%)") +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x = element_blank(),
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

### shaded area for the Average +

highlight_df <- attrition %>% 
  filter(year == 2019)

ggplot(data=attrition , aes(x=year, y=rate)) +
  geom_line(color="royalblue", size = 1.75) +


  
  geom_rect(aes(xmin=2010, xmax=2019, ymin=0, ymax= 7.5), alpha= 0.01, fill = "royalblue") +
  
  
  geom_point(data = highlight_df, 
             aes(x = year,y = rate), 
             color = "royalblue",size=4) +
  
  annotate("segment", x = 2010, xend = 2019, y = mean(rate), yend = mean(rate), color = "royalblue",linetype="dashed") +
  
  annotate("text", x =2018.25,  y = 6.5, label = "AVG: 7.5%", color = "royalblue") + 
  annotate("text", x = 2018.75,  y = 10.5, label = "9.1%", color = "royalblue") + 
  # shading

  # Set Origin of ggplot2 Plot Axes to Zero
  scale_x_continuous(expand = c(0, 0), limits = c(2010, 2019.2), n.breaks = 9) + # this is a good w and simple way to generat breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(0, 16), n.breaks = 9) + 
  

  ggtitle("Attrition rate over time") +

  ylab("Attrition rate (%)") +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x=element_blank(), # remove year
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

Area graph

ggplot(attrition, aes(x = year, y = rate)) +
  geom_area(fill='royalblue', colour = "royalblue", size = 1) +
  # scale_fill_brewer(palette = "Blues") ne marche pas +

  
  
  annotate("segment", x = 2010, xend = 2019, y = mean(rate), yend = mean(rate), color = "royalblue",linetype="dashed") +

  annotate("text", x =2018.25,  y = 6.5, label = "AVG: 7.5%", color = "white") +

  # Set Origin of ggplot2 Plot Axes to Zero
  scale_x_continuous(n.breaks = 9) + 
    # this is a good and simple way to generate breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(0, 16), n.breaks = 9) + 
  

  ggtitle("Attrition rate over time") +

  ylab("Attrition rate (%)") +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x=element_blank(), # remove year
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

ggplot(attrition, aes(x = year, y = rate)) +
  geom_bar(stat = "identity", fill='royalblue', colour = "royalblue", size = 1) +
  # scale_fill_brewer(palette = "Blues") ne marche pas +

  
  
  annotate("segment", x = 2010, xend = 2019, y = mean(rate), yend = mean(rate), color = "royalblue",linetype="dashed") +

  annotate("text", x = 2011.5,  y = 6.5, label = "AVG: 7.5%", color = "blue") +

  # Set Origin of ggplot2 Plot Axes to Zero
  scale_x_continuous(n.breaks = 9) + 
    # this is a good and simple way to generate breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(0, 16), n.breaks = 9) + 
  

  ggtitle("Attrition rate over time") +

  ylab("Attrition rate (%)") +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x=element_blank(), # remove year
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

year <- c(rep(2012:2019,2))
score <- c(795, 800,    804,    812,    830,    832,    824,    846, 774,   785,    805,    833,    839,    843,    827,    836)
category <- c(rep("Industry Average", 8), rep("Financial Saving",8))
data <- data.frame(year, category, score)
data
##    year         category score
## 1  2012 Industry Average   795
## 2  2013 Industry Average   800
## 3  2014 Industry Average   804
## 4  2015 Industry Average   812
## 5  2016 Industry Average   830
## 6  2017 Industry Average   832
## 7  2018 Industry Average   824
## 8  2019 Industry Average   846
## 9  2012 Financial Saving   774
## 10 2013 Financial Saving   785
## 11 2014 Financial Saving   805
## 12 2015 Financial Saving   833
## 13 2016 Financial Saving   839
## 14 2017 Financial Saving   843
## 15 2018 Financial Saving   827
## 16 2019 Financial Saving   836
ggplot(data = data, 
       aes(x= year, y = score,group=category, color = category))+
  geom_line() +
  
  
  scale_x_continuous(n.breaks = 7) + 
    # this is a good and simple way to generate breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(700, 900), n.breaks = 10) +
  
  theme(plot.title = element_text(size=18),
        
        axis.text=element_text(size=12),
        
        axis.title=element_text(size=12),
        axis.title.x=element_blank(), # remove year
        axis.line.x= element_line(color="grey", size = 1),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,1,1,1),"cm")) # to change the margin top, right. bottom. left

library(ggtext)
## Warning: package 'ggtext' was built under R version 4.0.5
ggplot(data = data, 
       aes(x= year, y = score))+
  geom_line(data = filter(data, category == "Industry Average"), size = 1.5, color =  "black") +  # bright navy blue
  geom_line(data = filter(data, category == "Financial Saving"), size = 1.5, color =  "blue") +
  
  geom_point(data = filter(data, category == "Industry Average", year == 2019), size = 4, color =  "black") +  
  geom_point(data = filter(data, category == "Financial Saving", year == 2019), size = 4, color =  "blue") +
  
  annotate("text", x = 2020.2, y = 850, label = "Industry Average", color = "black") + 
  annotate("text", x = 2020.2, y = 837.5, label = "Financial Savings", color ="blue") + 
  
  scale_x_continuous(expand = c(0, 0),n.breaks = 10) +
  coord_cartesian(xlim = c(2012, 2019), clip = 'off') + 
  # this is a good and simple way to generate breaks for scale_x_continuous
  scale_y_continuous(expand = c(0, 0),limits = c(700, 900), n.breaks = 10) +
  
  
  labs(title = "BRANCH SATISFACTION",
       subtitle = "Financial Savings below industry for the first 5 years") +

  ylab("SATISFACTION SCORE") +
  xlab("SURVEY YEAR") +
  theme(plot.title = element_text(size=16, vjust = 6, hjust = -0.25),
        plot.subtitle = element_text(size = 20, vjust = 5 , hjust = 0.55),
        # plot.title.position = "plot", # applied for subtitle
        #plot.subtitle = element_markdown(size=16, hjust = 1), # when using ggtext package
        

        # Adjust Space Between ggplot2 Axis Labels and Plot Area
        axis.text.x = element_text(size=12, vjust = -2) ,
        axis.text.y = element_text(size=12, hjust = -3), # ca marche pas cet commande
        
        axis.title.x= element_text(size = 12, hjust = 0, vjust = -4, color ="black"), # change the position of label on y axis
        axis.title.y = element_text(size = 12, hjust =1.05, vjust = 5 , color ="black"),# change the position of label on x axis
        
        # axis.title.x=element_blank(), 
        axis.line.x= element_line(color="grey"),
        axis.line.y= element_line(color="grey", size = 1),
        # axis.text.y = element_blank(),
        legend.position = "none",
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        plot.margin=unit(c(1,4.5,1,1),"cm")) # to change the margin top, right. bottom. left # work with coord_cartesian()