Home > OS >  Error when trying to map aesthetics with geom_signi
Error when trying to map aesthetics with geom_signi

Time:12-01

I am trying to create a faceted boxplot with significance levels indicated as asterisks like '***'. The problem is, I am getting an error when trying to add the geom_signif layer.

Warning message: Ignoring unknown aesthetics: xmin, xmax, annotations, y_position, map_signif_level

This is my data

 veg_un <- structure(list(Datum = structure(c(3L, 3L, 1L, 1L, 3L, 3L, 2L, 
3L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 3L, 1L, 2L, 2L, 2L), .Label = c("2021-04-08", 
"2021-05-17", "2021-07-07"), class = "factor"), Soll = c("1192", 
"1192", "149", "2484", "552", "172", "1192", "1189", "2484", 
"552", "552", "552", "119", "1192", "2484", "1202", "149", "552", 
"1202", "1202"), Entfernung = structure(c(2L, 1L, 1L, 2L, 2L, 
2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("2", 
"5"), class = "factor"), DGUnkraut = c(0, 1.3, 0.3, 3.4, 0, 2.5, 
4, 0, 1, 0.9, 0, 0.8, 0.5, 3, 1, 0.2, 0.2, 4, 0.5, 5)), row.names = c(NA, 
-20L), class = "data.frame")

And this is my code so far.

library(tidyverse)
library(ggsignif)
library(ggpubr)

anno_df <- compare_means(DGUnkraut ~ Entfernung, group.by = "Soll", data = veg_un, p.adjust.method = "holm") %>%
  mutate(y_pos = 7, p.adj = format.pval(p.adj, digits = 2))

ggplot(veg_un, aes(x=Entfernung, y=DGUnkraut))   
  geom_boxplot(position=position_dodge())   
  geom_point(aes(color=Entfernung), position=position_jitterdodge())   
  facet_wrap(~Soll)   
  theme_minimal() 
  ggsignif::geom_signif(
    inherit.aes = F,
    data=anno_df, 
    aes(xmin=group1, xmax=group2, annotations=p.adj, y_position=y_pos, map_signif_level = T),
    manual=TRUE)

I dont know why this is happening. Also, the p-values are way too high. I tried to modify this with y_position, but since I cant control the aesthetics, it doesnt work. Any help is really appreciated! Cheers

CodePudding user response:

I would try one of these

anno_df <- compare_means(DGUnkraut ~ Entfernung, group.by = "Soll", data = veg_un, p.adjust.method = "holm") %>%
  mutate(y.position = 7, p.adj = format.pval(p.adj, digits = 2))

p <- ggplot(veg_un, aes(x=Entfernung, y=DGUnkraut))   
  geom_boxplot(position=position_dodge())   
  geom_point(aes(color=Entfernung), position=position_jitterdodge())   
  facet_wrap(~Soll)   
  theme_minimal() 
  
p   ggsignif::geom_signif(comparisons = list(c("2", "5")), map_signif_level = T)
p   ggpubr::stat_pvalue_manual(anno_df, label = "p.adj") 

CodePudding user response:

I see several things.

  1. Your p.adj is 1 all the time. So I can't create a label with *

  2. Although you are receiving some warnings I am not receiving any error and the code is doing what I expected.

  3. You can resize the ylim and define the height of the labels.

library(tidyverse) library(ggsignif) library(ggpubr)

  anno_df <- compare_means(DGUnkraut ~ Entfernung, group.by = "Soll", data = veg_un, p.adjust.method = "holm") %>%
    mutate(y_pos = 5, label = format.pval(p, digits = 2))
  
  ggplot(veg_un, aes(x=Entfernung, y=DGUnkraut))   
    geom_boxplot(position=position_dodge())   ylim(0,7)   
    geom_point(aes(color=Entfernung), position=position_jitterdodge())   
    facet_wrap(~Soll)   
    theme_minimal() 
    ggsignif::geom_signif(
      inherit.aes = F,
      data=anno_df, 
      aes(xmin=group1, xmax=group2, annotations=label, y_position=y_pos, map_signif_level = T),
      manual=TRUE)

I obtained this image. I hope is what you were looking for.

enter image description here

  • Related