Hi, I'm new to R so I'm not sure if I'm doing this correctly.

I have already added a geom_hline for each facet_grid using the following code:

y = ggplot(dat, aes(x, y)) +
  theme_classic() +
  geom_boxplot(aes(fill=group)) + facet_rep_grid(.~group, scales = 'free', ) +
 scale_fill_manual(values=color_scheme)

p1 = y +
  geom_hline(aes(yintercept=healthy.baseline.mean, linetype="Line 1"),
             linetype='dotted', color='red', show.legend = TRUE)

But the legend for the geom_hline looks something like this:
Screen Shot 2022-08-04 at 12.11.35 PM
Looks like the geom_hline for each panel in the facet_grid was supperimposed to the boxplot legend.
How can I make a separate legend for the geom_hline such that I have five boxplot legend and 1 red-dotted legend for the geom_hline?

P.S. The geom_hline is the same for all panel because it represents the mean across data group.

Thanks!

1 Like

Hi @jarjarbinks , try to put a reproducible example of the data, this is better way for undestand well the situation and the community could help you.

Sometimes like this:

Paste the result of dput(dat[1:30 , ] For share the first 30 rows and all columns.