---
title: Code for Figure 3B JEXBIO/2021/242677
author: Toni Wöhrl
date: April 2021
output: html_document
editor_options: 
  chunk_output_type: console
---
# Init

```{r}

library(ggplot2)
library(tidyr)

```


# Read Data
```{r}
d <- read.csv(file = "Fig4B_Data.csv", header = TRUE, sep = ",", dec = ".")

head(d)

# group data: (CoG Moment and Leg Moment), (Total Moment)
d.grouped <- d %>%
  pivot_longer(cols=c("CoGMoment_TA1","LegMoment_TA1","TotalMoment_SumTA1"),
               names_to = c("Moment","MomentGroup"),
               names_sep="_"
  )
head(d)

```



# Plot 

```{r}

ggplot(d.grouped,
       aes(x=t,y=value,color=Moment,group=Moment))+
  facet_grid(MomentGroup~ant)+
  stat_summary(
    fun.data = "mean_cl_boot",
    geom = "smooth",
    se = TRUE
  )+
  geom_hline(yintercept = 0,linetype="dashed")+
  ylab("Moment of force in mN.mm")+
  xlab("Three-point contact duration in %")+
  theme_bw()+
  theme(legend.position = 'bottom')+
   scale_color_manual(
     values=c(CoGMoment="firebrick2",
             LegMoment= "steelblue2",
             TotalMoment = "black"
             )
    )

```

