Adding legend of all geoms when plotting multiple geoms on one figure

Task - to create a single figure showing four outputs:
species abundance (geom_bar, with fill as species and within aesthetics),
water_depth (geom_line, simple x and y continuous variable. Have included colour = blue outside the aes so that the line is blue).
river_height (geom_line, simple x and y continuous variable. This line defaults to grey which is fine)
treatment (geom_point, yes or no defined by symbols. I have subsetted the dataset to only show the 'yes' value, and set y= -5 so that the symbols (black squares) show below y = 0)

Aim - to have a simple legend that shows all the geoms. Currently, can only get the legend to show species names - I assume because fill is included in the aes, and I have used scale_fill_manual to define colours.

My question is - how can I get the legend to have a simple list of all the geoms? I need to add blue line (water_depth), grey line (river height), black squares (treatment).

ggplot() +
  geom_bar(data = dat2_site, aes(y=count_l_site, x=date, fill=f_grp), position="stack",stat="identity") +
  geom_line(data = dat2_site, aes(y=2*water_depth, x=date)) +
  geom_point(data = subset(dat2_site, treatment=='yes'), aes(y=-5, x=date, shape = treatment), size = 3, shape = 17) +
  geom_line(data = dat_twyford, aes(x = date, y=50*value, colour = value), colour = 'blue') +
  facet_wrap(~site,ncol=3) +
  scale_fill_manual(values = cols_species, name = 'Species')
  scale_y_continuous(expand = c(0,0), limits=c(-5, 100), sec.axis = sec_axis(~./2, name = 'Water depth (cm)')) 
  scale_x_date(date_breaks = "1 month", date_labels =  "%b") ```

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.