忽略未知的美学:填充

时间:2018-10-28 06:16:41

标签: r ggplot2 geom-text

在使用geom_text在箱图中输入值时出现警告。 经过研究,可以判断geom_text的aes中没有“填充”选项。

我想知道应该怎么做才能消除警告消息。

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

1 个答案:

答案 0 :(得分:1)

尝试以下

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))

如果无法正常工作,请共享一个minimal reproducible dataset


一般建议:不要写ggplot(data = scat, aes(x = scat$Species, y = scat$d13C)) + ...,而要在aes中使用裸列名称。