getting error while adding geom_significance in R
Hello,
I am using below code for box plot with geom significance but getting plot without adding significance value? I am interested to add geom significance value based on region.
My data structure is like this:
'data.frame': 54 obs. of 14 variables:
$ SampleType : Factor w/ 6 levels "2W_B_1Ash","2W_B_2Farm",..: 4 5 6 4 5 6 4 5 6 4 ...
$ Region : Factor w/ 2 levels "Barind","Madhupur": 2 2 2 2 2 2 2 2 2 2 ...
$ Village_site: Factor w/ 18 levels "Bandiya","Bogajan",..: 18 18 18 12 12 12 1 1 1 2 ...
$ Season : Factor w/ 1 level "2W": 1 1 1 1 1 1 1 1 1 1 ...
$ Treatment : Factor w/ 3 levels "Ash","AshPlusFarmerPractise",..: 1 3 2 1 3 2 1 3 2 1 ...
$ S_Mn : num 365 363 366 389 369 ...
$ S_Ni : num 20.2 18.9 21 19.3 25.6 ...
$ S_P : num 445 435 505 318 381 ...
$ S_Rb : num 102.7 99.7 98.9 94 97.1 ...
$ S_S : num 191 187 191 129 171 ...
$ S_Si : num 302667 302333 301333 293333 301667 ...
$ S_Sr : num 123 123 122 147 143 ...
$ S_Zn : num 73.5 77.7 80.5 77.7 79.9 ...
$ pH : num 5.24 4.76 5.3 6.72 5.44 6.29 4.41 4.95 4.69 5.08 ...
library(reshape2)
library(ggplot2)
library(multcompView)
library(tidyverse)
library(ggsignif)
library(ggpubr)
list.files()
bpdata <- read.table("Soil1.chemical.txt", sep="\t", header=TRUE)
dput(bpdata)
str(bpdata)
bpdata[,"SampleType"] <- as.factor(bpdata[,"SampleType"])
bpdata <- cbind(row.names(bpdata),bpdata)
names(bpdata)[1] <- "sample"
#create paired comparison for box plots
bpdata$Region <- factor (bpdata$Region, levels = c("Madhupur", "Barind"))
cmpr <- list(c("Madhupur","Barind"))
data <- melt(bpdata, id = 1:6,variable.name="name")
v_factor_levels <- c("2W_B_1Ash", "2W_B_2Farm", "2W_B_3AshFarm", "2W_M_1Ash", "2W_M_2Farm", "2W_M_3AshFarm")
data$SampleType <- factor (data$SampleType, levels = v_factor_levels)
#df.m <- melt(bpdata, id.var = "SampleType")
library(ggsignif)
pdf("soil1.plot.pdf", width = 18, height = 12)
ncol=3
p <- ggplot(data = data, aes(x=SampleType, y=value,fill=SampleType)) +
theme_bw() +
theme(
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
plot.title = element_text(vjust = -8.5,hjust = 0.1),
line=element_line(size=1),
axis.text.x = element_text(size = 10, face ="bold", hjust = 0.5, colour = "black"),
axis.text.y = element_text(size = 12, face ="bold", hjust = 0.5, colour = "black"),
axis.ticks.x = element_blank()) +
theme(strip.background=element_rect(fill="white")) +
theme(strip.text=element_text(color="black",face="bold", size =14)) +
geom_boxplot(aes(fill=SampleType),outlier.colour = NA)
p + facet_wrap(.~name,scales="free_y", ncol = ncol) + geom_signif(comparisons = cmpr,step_increase = 0.2,size=0.5,textsize=3,map_signif_level = T,tip_length = 0.1,test =t.test,margin_top = 0.1)
dev.off();
warning;
Warning messages:
1: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
2: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
3: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
4: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
5: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
6: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
7: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
8: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
9: Computation failed in `stat_signif()`:
missing value where TRUE/FALSE needed
Thanks
• 2,222 views
•
link
0 answers
No answers yet.
Log in to answer this question.
Hi, according to the vignette it is preferable putting
test="t.test"in geom_signif arguments. Could the problem come from there ?Hello Bioinfonext!
We believe that this post does not fit the main topic of this site.
Not really related to bioinformatics
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!