I'm trying to make a legend for a series of plots. I only need the legend, not the actual graphs as I am creating them separately and have the correct formatting for these already. I will then add this universal legend.
Currently I have the code for 2 different color lines separated, but I'd ideally have one red straight line and one red dashed line. However, I can't make the line dashed on one of them and have both red. Currently the code has one as red and the other as purple. Both being straight lines.
# libraries
library(readr) # for function file.path
library(dplyr)
library(ggplot2)
library(tidyverse)
library(cowplot)
library(gridExtra)
library(extrafont)
legend <- data %>%
ggplot(aes_string(x='DateTime', y='Rel_mAOD')) +
geom_line() +
theme_classic() +
geom_vline(aes(xintercept=as.POSIXct('2020-11-03 01:00:00'),
col='red'), size=2) +
geom_vline(aes(xintercept=as.POSIXct('2021-11-01 01:00:00'),
col='purple'),linetype=2, size=2, showguide=TRUE) +
scale_color_manual(
name=NULL,
values=c('red','purple'),
labels=c('Release', 'Main')) +
theme(legend.direction='horizontal',
legend.position='top',
legend.text=element_text(size=30, margin=margin(r=1, unit='inch')),
legend.spacing.x=unit(0.5, 'inch')) +
guides(fill=guide_legend(
keywidth=6,
keyheight=6,
default.unit='inch'))
my_legend<-get_legend(legend)
plot(my_legend)
Use
scale_linetype_manual
, and just have both lines colored red:To have additional labels :