Data Construction

my_date <- as.Date("2015-01-01")
df <- data.frame(
  data = my_date %m+% years(0:5)
  , class = c(
    rep('Fundraiser', 6),
    rep('Wedding', 6),
    rep('Offsite', 6),
    rep('Holiday', 6),
    rep('Prom', 6)
  )
  , value = c(
    13000, 13250, 15000, 15750, 16250, 19700 # Fundraiser
    , 18750, 18500, 18550, 18600, 18575, 18800 # Wedding
    , 11600, 11450, 12300, 10500, 12850, 15700 # Offsite
    , 16000, 16050, 15750, 15250, 14750, 14400 # Holiday
    , 11500, 12250, 12300, 12300, 12900, 12800# Prom
  )/1000
)

head(df, 6)
##         data      class value
## 1 2015-01-01 Fundraiser 13.00
## 2 2016-01-01 Fundraiser 13.25
## 3 2017-01-01 Fundraiser 15.00
## 4 2018-01-01 Fundraiser 15.75
## 5 2019-01-01 Fundraiser 16.25
## 6 2020-01-01 Fundraiser 19.70

Data Manipulation

# Construction of flag variable
# Meant to flag if the data is a forecast or not
# it'll be use to change the format of the line

df %<>% mutate(
  flag = ifelse(year(data) == 2020, 'Y', 'N')
)

head(df, 6)
##         data      class value flag
## 1 2015-01-01 Fundraiser 13.00    N
## 2 2016-01-01 Fundraiser 13.25    N
## 3 2017-01-01 Fundraiser 15.00    N
## 4 2018-01-01 Fundraiser 15.75    N
## 5 2019-01-01 Fundraiser 16.25    N
## 6 2020-01-01 Fundraiser 19.70    Y
# Construction of fund_color variable
  # Meant to flag if the data is the forecast of Fundraiser
  # it'll be use to change the color of the color on that line segment

df %<>% mutate(
  fund_color = ifelse(year(data) == 2020 & class == 'Fundraiser', '#287fd5', '#a6a6a6')
)

head(df, 6)
##         data      class value flag fund_color
## 1 2015-01-01 Fundraiser 13.00    N    #a6a6a6
## 2 2016-01-01 Fundraiser 13.25    N    #a6a6a6
## 3 2017-01-01 Fundraiser 15.00    N    #a6a6a6
## 4 2018-01-01 Fundraiser 15.75    N    #a6a6a6
## 5 2019-01-01 Fundraiser 16.25    N    #a6a6a6
## 6 2020-01-01 Fundraiser 19.70    Y    #287fd5
# Theme for the plot

theme_padrao <- theme_light()+
  theme(
    panel.grid.major = element_blank()
    , panel.grid.minor = element_blank()
  )

Plot Construction

# ggplot Default

df %>% ggplot(aes(x = data, y = value, color = class))+
  geom_line()

# First Change

ggplot()+
  geom_line(
    data = df,
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    size = 1.5
  )+
  ylab('AVG REVEUE PER EVENT')+
  xlab('')+
  theme_classic()

# Add Color names

ggplot()+
  geom_line(
    data = df,
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    size = 1.5
  )+
  geom_text(
    data = df %>% filter(flag == 'Y')
    , aes(x = year(data)+.3, y = value, label = class, group = class)
  )+
  ylab('AVG REVEUE PER EVENT')+
  xlab('')+
  theme_classic()

# Separate linetype for the year 2020
  # year < 2020 Solid
  # year = 2020 dashed


ggplot()+
  geom_line(
    data = df %>% filter(flag == 'N'),
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    size = 1.5
  )+
  geom_line(
    data = df %>% filter(year(data) >= 2019),
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    linetype = 'dotted',
    size = 1.5
  )+
  geom_text(
    data = df %>% filter(flag == 'Y')
    , aes(x = year(data)+.3, y = value, label = class, group = class)
  )+
  ylab('AVG REVEUE PER EVENT')+
  xlab('')+
  theme_classic()

# Add a point in the Foundraiser
# Change label

ggplot()+
  geom_line(
    data = df %>% filter(flag == 'N'),
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    size = 1.5
  )+
  geom_line(
    data = df %>% filter(year(data) >= 2019),
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    linetype = 'dotted',
    size = 1.5
  )+
  geom_text(
    data = df %>% filter(flag == 'Y') %>% mutate(l = paste0('$',value,'k ', class))
    , aes(x = year(data)+.7, y = value, label = l, group = class)
  )+
  geom_point(
    data = df %>% filter(fund_color != '#a6a6a6')
    , aes(x = year(data), y = value)
    , shape = 1, size = 5, stroke = 2
    , color = '#a6a6a6'
  )+
  #scale_color_manual(data = df, values = fund_color)+
  ylab('AVG REVEUE PER EVENT')+
  xlab('')+
  xlim(c(2015,2021))+
  theme_classic()

# Select the color on the line when the data follows the rule
# Is from class Fundraiser and 2020

ggplot()+
  geom_line(
    data = df %>% filter(flag == 'N'),
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    size = 1.5
  )+
  geom_line(
    data = df %>% filter(year(data) >= 2019 & class != 'Fundraiser'),
    aes(x = year(data), y = value, group = class),
    color = '#a6a6a6',
    linetype = 'dotted',
    size = 1.5
  )+
  geom_text(
    data = df %>% filter(flag == 'Y') %>% mutate(l = paste0('$',value,'k ', class))
    , aes(x = year(data)+.7, y = value, label = l, group = class)
  )+
  geom_point(
    data = df %>% filter(fund_color != '#a6a6a6')
    , aes(x = year(data), y = value)
    , shape = 1, size = 5, stroke = 2
    , color = '#287fd5'
  )+
  geom_line(
    data = df %>% filter(year(data) >= 2019 & class == 'Fundraiser')
    , aes(x = year(data), y = value)
    , color = "#287fd5"
    , linetype = 'dotted'
    , size = 2
  )+
  #scale_color_manual(data = df, values = fund_color)+
  ylab('AVG REVEUE PER EVENT')+
  xlab('')+
  ylim(c(0,25))+
  xlim(c(2015,2021))+
  theme_classic()