Skip to content
Snippets Groups Projects
Commit 1d4fd663 authored by Xianzong Meng's avatar Xianzong Meng
Browse files

this code is for practice only, to make figs look better

parent 3ee20bf5
No related branches found
No related tags found
No related merge requests found
## packages loading
```{r}
#General utility packages
library(tidyverse)
library(glue)
library(knitr)
library(data.table)
#Stats packages
library(lme4)
library(multcomp)
library(parameters)
library(effectsize)
library(performance)
library(emmeans)
#Plot packages
library(ggpubr)
```
```{r}
df <- read_csv('C:/Users/xiamen/Desktop/data_for_R/modified_robogator_paper/robotmod_data.csv') %>%
mutate(trials = as.factor(trials)) %>%
mutate(group = as.factor(group)) %>%
mutate(sex = as.factor(sex)) %>%
mutate(rat_ID = as.factor(rat_ID)) %>%
mutate(restriction = as.factor(restriction))%>%
mutate(age = as.factor(age))%>%
mutate(food.distance.cm = as.factor(food.distance.cm))%>%
# Create score based on time. Following log attribution of score as a function of time.
mutate(leaving.score = case_when(is.na(leaving.sec) ~ 7,
leaving.sec >= 200 ~ 6,
leaving.sec >= 100 ~ 5,
leaving.sec >= 50 ~ 4,
leaving.sec >= 25 ~ 3,
leaving.sec >= 12.5 ~ 2,
leaving.sec >= 6.25 ~ 1,
leaving.sec <6.25 ~ 0)) %>%
mutate(approaching.score = case_when(is.na(approaching.sec) ~ 7,
approaching.sec >= 200 ~ 6,
approaching.sec >= 100 ~ 5,
approaching.sec >= 50 ~ 4,
approaching.sec >= 25 ~ 3,
approaching.sec >= 12.5 ~ 2,
approaching.sec >= 6.25 ~ 1,
approaching.sec <6.25 ~ 0)) %>%
mutate(backing.score = case_when(is.na(backing.sec) ~ 7,
backing.sec >= 200 ~ 6,
backing.sec >= 100 ~ 5,
backing.sec >= 50 ~ 4,
backing.sec >= 25 ~ 3,
backing.sec >= 12.5 ~ 2,
backing.sec >= 6.25 ~ 1,
backing.sec <6.25 ~ 0)) %>%
mutate(foraging.score = case_when(is.na(foraging.sec) ~ 7,
foraging.sec >= 200 ~ 6,
foraging.sec >= 100 ~ 5,
foraging.sec >= 50 ~ 4,
foraging.sec >= 25 ~ 3,
foraging.sec >= 12.5 ~ 2,
foraging.sec >= 6.25 ~ 1,
foraging.sec <6.25 ~ 0))
#head(df) %>% kable("pipe")
```
```{r}
df.SD_Rday1 <- df %>% filter(df$robot.day == 1, df$group == "SD")
p_1 <- ggplot(df.SD_Rday1, aes(x=trials, y=foraging.score, group=rat_ID))
p_1 + geom_point(color="gray")+ geom_line(color="gray")+
stat_summary(fun=mean, aes(group = age, color= age), geom="line")+
stat_summary(fun.data = mean_se, aes(group=age, color = age), geom = "errorbar", alpha=1, width=0.05)+
scale_color_manual(values = c("red", "blue"))+
scale_y_continuous(breaks = seq(0, 7, by = 1))+
geom_jitter(alpha = 0.5,width = 0.1) + labs(x = "positions", y = "foraging score") + theme_minimal()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment