Prepare data and libraries
# clear workspace
rm(list = ls())
# Import
d <- read.table(file = "data.csv", header =TRUE, sep = ",", dec = ".",row.names=NULL)
head(d)
## deg ant data
## 1 0 F -1.7513761
## 2 0 F -2.1332912
## 3 0 F NA
## 4 0 F -1.8772059
## 5 0 F -0.9108808
## 6 0 F -1.8078323
# omit NA
d <- na.omit(d)
# load libraries
library(ggpubr)
library(rstatix)
Test grouped data
p <- d %>% group_by(ant) %>% wilcox_test(data ~ deg,paired=FALSE)
p
## # A tibble: 6 x 10
## ant .y. group1 group2 n1 n2 statistic p p.adj p.adj.signif
## * <chr> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
## 1 C data -60 0 43 44 1400 8.23e- 5 1.65e- 4 ***
## 2 C data -60 60 43 44 499 1.07e- 4 1.65e- 4 ***
## 3 C data 0 60 44 44 164 1.08e-13 3.24e-13 ****
## 4 F data -60 0 44 43 1259 8.00e- 3 1.50e- 2 *
## 5 F data -60 60 44 45 1349 3.00e- 3 9.00e- 3 **
## 6 F data 0 60 43 45 972 9.74e- 1 9.74e- 1 ns
Version 1 (stat_compare_means): Plot and test grouped data
ggboxplot(d, x = "deg", y = "data",
add = "jitter",
notch=TRUE)+
facet_grid(.~ant) +
geom_text(aes(label=paste("n=",..count..,sep="")), y=-4.1, stat='count', size=4) +
stat_compare_means(comparisons = list(c("0", "-60"),c("0", "60"),c("-60", "60")),
paired=FALSE,
# label="p.signif",
method = "wilcox.test",label.x = 1.45)+
stat_summary(fun = median, geom = "label",
size = 4,
hjust = -0.5,
aes(label=gsub("\\.",".",as.character(round(..y..,1)))))+
theme(strip.background = element_rect(fill = "white"))+
xlab("deg")+
ylab("data")
Version 2 (geom_signif): Plot and test grouped data
ggboxplot(d, x = "deg", y = "data",
palette = "npg",
add = "jitter",
notch=TRUE)+
facet_grid(.~ant) +
geom_signif(comparisons = list(c("0", "-60")),y_position = c(0.9,0),
# map_signif_level=TRUE,
test=wilcox.test)+
geom_signif(comparisons = list(c("0", "60")),y_position = c(1.2,0),
# map_signif_level=TRUE,
test=wilcox.test)+
geom_signif(comparisons = list(c("-60", "60")),y_position = c(1.5,0),
# map_signif_level=TRUE,
test=wilcox.test)+
stat_summary(fun = median, geom = "label",
size = 4,
hjust = -0.5,
aes(label=gsub("\\.",".",as.character(round(..y..,1)))))+
theme(strip.background = element_rect(fill = "white"))+
xlab("deg")+
ylab("data")