0

There was a warning when entering values ​​in the boxplot using geom_text. As a result of studying, it is judged that there is no 'fill' option in aes of geom_text.

I want to know what I should do to get rid of the warning message.

means <- aggregate(d13C~Species, data=scat, meam) 
means$d13C <- round(means$d13C,2)
ggplot(data=scat, 
       mapping=aes(x=scat$Species, y=scat$d13C, fill=scat$Species)) +
  geom_boxplot() +
  stat_summary(fun.y=mean, colour='darkred', geom="point", 
               shape=3, size=3, show.legend=F) +
  geom_text(data=means, 
            aes(x=means$Species, y = d13C+1, label=d13C, fill=Species))

enter image description here

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
monsoon
  • 17
  • 1
  • 6
  • 1
    I think you should remove fill=scat$Species as you do not use scale_fill_manual() or equivalent. – Aleksandr Oct 28 '18 at 07:28
  • `geom_text` does not understand `fill` aesthetics, see https://ggplot2.tidyverse.org/reference/geom_text.html#aesthetics. Remove it or replace it by `colour`. – bers Mar 03 '22 at 12:58

1 Answers1

1

Try the following

means <- aggregate(d13C ~ Species, data = scat, mean) # there was a typo here 
means$d13C <- round(means$d13C, 2)
ggplot(data = scat, aes(x = Species, y = d13C)) +
  geom_boxplot(aes(fill = Species)) +
  stat_summary(
    fun.y = mean,
    colour = 'darkred',
    geom = "point",
    shape = 3,
    size = 3,
    show.legend = F
  ) +
  geom_text(data = means, aes(x = Species, y = d13C + 1, label = d13C))

If not working properly, please share a minimal reproducible dataset.


A general advise: Don't write ggplot(data = scat, aes(x = scat$Species, y = scat$d13C)) + ... but use the bare column names in aes.

markus
  • 25,843
  • 5
  • 39
  • 58