I need to make a line plot in ggplot2 using a data frame called df that looks something like this:
DATE ITEM NUMBER_SOLD
<date> <chr> <int>
1 2018-01-08 APPLE 3
2 2018-01-09 APPLE 3
3 2018-01-09 PEAR 2
4 2018-01-09 ORANGE 1
5 2018-01-10 APPLE 2
6 2018-01-10 PEAR 1
7 2018-01-12 CHERRY 2
8 2018-01-12 MANGO 1
9 2018-01-15 PINEAPPLE 1
10 2018-01-15 APRICOT 1
etc
The data frame is basically a tibble showing how many times a particular item was sold on a given day in 2018 with a total of 336 rows.
The plot needs to be a line plot showing the sale of one particular item (apple) with the date on the x axis, number sold on the y axis and an additional line on the y axis showing a 15% increase in sales like this:
df %>% filter(ITEM == "APPLE") %>%
ggplot(aes(DATE, NUMBER_SOLD)) +
geom_line(size = 1, col = "red") +
theme(axis.text.x = element_text(angle = 90)) +
geom_line(aes(y = NUMBER_SOLD + NUMBER_SOLD/100*15), col = "green4", size = 1, alpha = 0.6) +
scale_x_date(date_labels="%b", date_breaks = "1 month")
However, I would also need to add a legend to show what both lines represent, e.g. red colored line representing the original number of sales and the green one representing the original number of sales + 15%. How might I achieve that?