geom_label with custom background and color (text)

Here is the code that finally worked. I had to use as.factor() and then used hex values. Thanks to @raytong for all your help.

p<-ggplot(tchart, aes(x = beatenLengths,y = OffRail)) +
  geom_point() + 
  geom_label(aes(label=pgm, fill= as.factor(pgm), color= as.factor(pgm)),  size = 3.0) +
  geom_convexhull(alpha = 0.2, fill = "blue") +
  scale_fill_manual(values = c("#ec2c28","#FFFFFF","#1d4fa3","#EAE824","#458544","#060103","#EFA428","#f9bcc5", "#1FB8D7","#9A4687","#C2C2C2","#a9d5b5")) +
  scale_color_manual(values = c("#FFFFFF", "#000000", "#FFFFFF", "#000000", "#FFFFFF", "#EAE824", "#000000", "#000000","#000000","#000000","#000000","#000000")) +
  facet_wrap(~ Sixteenth, ncol=4) +
  theme_fivethirtyeight() +
  theme(legend.position = "none")
1 Like