Search code examples
rggplot2legendaesthetics

How to hide legend for geom_label only in ggplot?


I have a ggplot object to plot an outcome by days of the week as such:

ggplot(weekdays, aes(x=weekday, fill=weekday, y=outcome_mean, ymin=outcome_lci, ymax=outcome_uci)) +
  geom_col() +
  geom_errorbar() +
  theme_bw() +
  geom_label(aes(label=paste(visits, "Visits", sep=" ")), y=-0.75, size=3.5, color="black", fontface="bold") +
labs(y="Outcome Mean", x="Weekday", title = "Outcome by Weekday", fill="Weekday:") +
  theme(panel.grid.minor = element_line(colour="lightgrey", size=0.5)) +
  theme(panel.grid.major = element_line(colour="lightgrey", size=0.5)) +
  theme(axis.text.x = element_text(face="bold", size=10)) +
  theme(axis.text.y = element_text(face="bold", size=12)) +
  theme(axis.title.x = element_text(face="bold", size=16)) +
  theme(axis.title.y = element_text(face="bold", size=16)) +
  theme(legend.text= element_text(face="bold", size=12)) +
  theme(legend.title= element_text(face="bold", size=14)) +
  theme(plot.title= element_text(face="bold", size=16, hjust=0.5)) +
  #scale_label(guide=FALSE) +
  scale_y_continuous(limits=c(-1,20), breaks= seq(0,30,2), minor_breaks=seq(0,30,1)) 

which gives:

image of ggplot graph

However I don't like the little "a" symbols in the fill legend, how do I get rid of these without hiding the entire legend (as in some of my plots x and fill are different variables so I would need to keep the fill legend)?

I have tried adding "scale_label(guide=FALSE)" (shown commented out above) but this is not a recognised function.

Does anyone know how I can achieve this?


Solution

  • ...
    geom_label(..., show.legend = FALSE) +
    ...
    

    https://ggplot2.tidyverse.org/reference/geom_text.html