I followed the general structure of the links below to plot two geom_boxplot
's on top of each other, with the end goal of having the whiskers of one boxplot be dashed. I succeeded, but now there are two legends that I think correspond to each of the boxplots.
How to modify whiskers of a boxplot in ggplot2?
How to customize whisker lines on a geom_box plot differently than the lines of the box itself
t = ggplot(data = graph_data) +
geom_boxplot(aes(x = data_source, ymin = lwo, lower = pct_25, middle = median,
upper = pct_75, ymax = uwo, fill = data_source, linetype = data_source),
stat = 'identity', color = 'black') +
geom_boxplot(aes(x = data_source, ymin = pct_25, lower = pct_25, middle = median,
upper = pct_75, ymax = pct_75, fill = data_source),
stat = 'identity', color = 'black') +
geom_text(aes(x = data_source, y = -Inf, label = count_label),
vjust=-.5,stat='identity',size = 3,colour='Black',fontface='italic') +
theme_custom +
facet_grid(. ~ month, labeller = labeller(month = month_lbls)) +
theme(strip.background = element_rect(fill = NA)) +
theme(strip.text = element_text(size = rel(1.0), face = "bold")) +
scale_fill_manual(values = as.character(graph_colors), labels = names(graph_colors), guide = guide_legend(title = "Data Source")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
theme(panel.margin = unit(3, "points")) +
theme(panel.grid.major.x = element_blank()) +
theme(panel.grid.minor.x = element_blank())
In the first geom_boxplot
, the I specify the different line_type
then overlay the interquartile range in the second geom_boxplot
with a solid line. I think these two boxplot additions are creating the two legends, any ideas on how to remove the top legend (titled 'data_source')?