---
title: Code for Figure 2B JEXBIO/2021/242677
author: Toni Wöhrl
date: April 2021
output: html_document
editor_options: 
  chunk_output_type: console
---
# Read data
```{r}
d<-read.csv("Fig2B_Data.csv")
head(d)
```


# Bootstrapping with dabestr
```{r}
# group data for Multi-two group comparisons
d$Group <- NaN
d$Group[which(d$ant=="Formica" & d$slope==0)] <- "ControlF"
d$Group[which(d$ant=="Formica" & d$slope==60)] <- "UpslopeF"
d$Group[which(d$ant=="Cataglyphis" & d$slope==0)] <- "ControlC"
d$Group[which(d$ant=="Cataglyphis" & d$slope==60)] <- "UpslopeC"
head(d)

library(dabestr)

# unpaired Multi-two group analysis
# https://cran.r-project.org/web/packages/dabestr/vignettes/using-dabestr.html
d_dabestr <- dabest(d, Group, ssm,
                             idx = list(c("ControlC","UpslopeC"),
                                        c("ControlF","UpslopeF")),
                             paired = FALSE)

d_dabestr

d_diff<-median_diff(d_dabestr,reps=5000) 
plot(d_diff,rawplot.ylim=c(-3.2,2),effsize.ylim=c(-2,3.2),float.contrast = F)

```

# Optional: Boxplot + Wilcox.test
```{r}
library('ggplot2')
library('ggpubr')


ggplot(d,aes(x=as.factor(slope),y=ssm))+
  geom_jitter(alpha=0.5,width=0.2)+
  geom_boxplot(alpha=0.5)+
  facet_grid(.~ant)+
  geom_text(aes(label=paste("n=",..count..,sep="")),
            y=-4.3,
            stat='count',
            size=4)+
  stat_compare_means(comparisons = list(c("0", "60")),
    aes(label = ..p.signif..),
    paired=FALSE, 
    method = "wilcox.test",
    method.args = list(alternative="less"),
    p.adjust.methods="bonferroni"
  )+
  stat_summary(fun = median, 
               geom = "label",
               size = 4,
               hjust = -0.6,
             #  alpha=0.8,
               aes(label=gsub("\\.",".",as.character(round(..y..,1)))))+
  theme_bw()+
  ylab("SSM(60) (mm)")+
  xlab("Kinematics")

```

