big behavior graph

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.3.0      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
behavior_23Feb23 <- read.csv("behavior_23Feb23.csv")

behaviorprop <- behavior_23Feb23

behaviorprop$stationaryprop = (behaviorprop$stationary/behaviorprop$total_alive)
behaviorprop$movingprop = (behaviorprop$moving/behaviorprop$total_alive)
behaviorprop$incubatingprop = (behaviorprop$incubating/behaviorprop$total_alive)
behaviorprop$feedingprop = (behaviorprop$feeding/behaviorprop$total_alive)
behaviorprop$fanningprop = (behaviorprop$fanning/behaviorprop$total_alive) 

behaviorprop <- behaviorprop %>%
  filter(fanningprop<=1)

behavior2 <- behaviorprop[,c(6,14,19,20,21,22,23)]

do i have to pivot the goddamn behaviors to get the goddamn average (i think so)

behavior3<- behavior2 %>%
  pivot_longer(stationaryprop:fanningprop,names_to='behaviors',values_to='prop')

head(behavior3)
# A tibble: 6 × 4
   temp infected behaviors       prop
  <int>    <int> <chr>          <dbl>
1    37        0 stationaryprop 0    
2    37        0 movingprop     0.333
3    37        0 incubatingprop 0.222
4    37        0 feedingprop    0.444
5    37        0 fanningprop    0.111
6    37        0 stationaryprop 0.143
behavior3$behaviors <- recode_factor(behavior3$behaviors, fanningprop="Fanning",stationaryprop="Stationary",movingprop="Moving",incubatingprop="Incubating",feedingprop="Feeding")

head(behavior3)
# A tibble: 6 × 4
   temp infected behaviors   prop
  <int>    <int> <fct>      <dbl>
1    37        0 Stationary 0    
2    37        0 Moving     0.333
3    37        0 Incubating 0.222
4    37        0 Feeding    0.444
5    37        0 Fanning    0.111
6    37        0 Stationary 0.143
beemean<-behavior3 %>% 
group_by(behaviors, temp, infected) %>% 
summarize(mean = mean(prop), sd=sd(prop),n=n(),se=sd/sqrt(n)) 
`summarise()` has grouped output by 'behaviors', 'temp'. You can override using
the `.groups` argument.
beemean
# A tibble: 50 × 7
# Groups:   behaviors, temp [25]
   behaviors  temp infected    mean     sd     n      se
   <fct>     <int>    <int>   <dbl>  <dbl> <int>   <dbl>
 1 Fanning      23        0 0       0        203 0      
 2 Fanning      23        1 0.0136  0.0563   132 0.00490
 3 Fanning      30        0 0.00415 0.0204   174 0.00154
 4 Fanning      30        1 0.00501 0.0223    82 0.00246
 5 Fanning      34        0 0.154   0.165     63 0.0208 
 6 Fanning      34        1 0.117   0.135    126 0.0120 
 7 Fanning      37        0 0.375   0.228    191 0.0165 
 8 Fanning      37        1 0.399   0.205    106 0.0199 
 9 Fanning      40        0 0.251   0.214     64 0.0267 
10 Fanning      40        1 0.176   0.152    136 0.0130 
# … with 40 more rows
beemean$temp=as.factor(beemean$temp)
beemean$infected=as.factor(beemean$infected)

ggplot(data=beemean,aes(x=behaviors, y=mean,color=temp,shape=infected))+
  geom_point()+
  geom_errorbarh(aes(xmax=mean+se, xmin=mean-se),height=0.2)+
  scale_shape_discrete(solid=T)+
  theme_classic()

This code is not working right now, package ggalt is saying it’s installing but then it’s actually not?? Therefore geom_dumbbell can’t work…

#install.packages('ggalt')
#library(ggalt)

beegraph <- ggplot(beemean, aes(x=mean, y=behaviors, group=behaviors)) + geom_dumbbell(color=“#a3c4dc”, size=0.75, point.colour.l=“#0e668b”) + scale_x_continuous(label=percent) + labs(x=NULL, y=NULL, title=“Average Behavior Props”, subtitle=“yas”, caption=“bees”) + theme(plot.title = element_text(hjust=0.5, face=“bold”), plot.background=element_rect(fill=“#f7f7f7”), panel.background=element_rect(fill=“#f7f7f7”), panel.grid.minor=element_blank(), panel.grid.major.y=element_blank(), panel.grid.major.x=element_line(), axis.ticks=element_blank(), legend.position=“top”, panel.border=element_blank())