1

I have a facet wrap of 8 plots and I want to rename the Legend, it currently defaults to the fill value Depth_bins but I want to be able to change that. I've tried various methods, including the below using scale_color_discrete but nothing changes the title. I'm assuming this is because it's a facet_wrap.

facet_8 <- ggplot(am_dives, aes(x = st_hr, fill = Depth_bins)) +
  geom_density(aes(y = ..count../sum(..count..)), position = "stack", alpha = 0.7) +
  scale_x_datetime(date_labels = "%H:%M") +
  labs(x = "Start hour", y = "Density") + 
  facet_wrap(~ID, dir = "v", scales = "free_y") + 
  scale_color_discrete(name = "Depth Bins")
facet_8

any help much appreciated!

R student
  • 109
  • 6

1 Answers1

2

I think the labs function should work as mentioned here:

How to change legend title in ggplot

So, something like this:

facet_8 <- ggplot(am_dives, aes(x = st_hr, fill = Depth_bins)) +
  geom_density(aes(y = ..count../sum(..count..)), position = "stack", alpha = 0.7) +
  scale_x_datetime(date_labels = "%H:%M") +
  labs(x = "Start hour", y = "Density") + 
  facet_wrap(~ID, dir = "v", scales = "free_y") + 
  labs(fill = "Your Title Here")
facet_8
hglanz
  • 86
  • 6
  • so simple, i tried labs(legend = ) and all kinds of others but didn't think to put fill. makes sense now. Thank you! – R student Oct 26 '21 at 07:14