Project Part 4 Plots

Project Part 4: Exploratory Data Visualization

PLOT 1

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()
library(ggplot2)

behavior_23Feb23 <- read.csv("behavior_23Feb23.csv")

behavior <- behavior_23Feb23

behavior$temp=as.character(behavior$temp)

ggplot(data=behavior, aes(x=day_of_experiment, y=total_alive, color=temp))+
geom_bar(stat="identity")+
  xlim(0,10)+
  theme(axis.text=element_text(size=10))+
  labs(x='Days in Experiment',y='Total Alive',title='Survivorship')+
  theme(plot.title=element_text(hjust=0.5))
Warning: Removed 1064 rows containing missing values (`position_stack()`).
Warning: Removed 87 rows containing missing values (`geom_bar()`).

This plot is interesting for a visualization of total bees alive over the course of the experiment. It is important to see that the count goes up over time, which suggests some human error in recording behavior…

PLOT 2

ggplot(data=behavior,aes(x=observer_initials, y=moving))+
  geom_boxplot()+
  theme_classic()
Warning: Removed 728 rows containing non-finite values (`stat_boxplot()`).

In data collection, I found that accurately counting the moving bees was difficult, so I thought it would be cool to visualize moving counts by observer. This plot seems to tell me that later in this project, using observer as a random effect will probably be a good idea.

PLOT 3

pd = position_dodge(width= 1)
behavior$infected=as.factor(behavior$infected)

behavior_meanfanning<- behavior %>%
group_by(temp,infected) %>%
drop_na(fanning) %>%
summarize(meanfanning = mean(fanning), sd=sd(fanning),n=n(),se=sd/sqrt(n), infected=infected)
`summarise()` has grouped output by 'temp', 'infected'. You can override using
the `.groups` argument.
ggplot(data=behavior_meanfanning, aes(x=temp,y=meanfanning, color=infected))+
geom_point(position=pd)+
geom_errorbar(data=behavior_meanfanning, aes(x=temp, ymin=meanfanning-se,ymax=meanfanning+se), position=pd)+
  theme_classic()+
  theme(axis.text=element_text(size=10))+
  labs(x='Temperature',y='Average Fanning',title='Average Fanning Behavior by Temp')+
  theme(plot.title=element_text(hjust=0.5))

This is visualizing the average number of fanning bees across different temperatures. It is split by infection status to see if fanning behavior differs based on if the bee is sick or not. I think it is cool to see that the bees “give up” as the temperature goes from 37 to 40 degrees C.

PLOT 4

ggplot(data=behavior, aes(x=temp, y=incubating))+
  geom_boxplot()+
  theme_classic()
Warning: Removed 728 rows containing non-finite values (`stat_boxplot()`).

This is a boxplot of incubating count by temperature. I think that this is a cool way to visualize how temperature impacts reproductive behavior.

PLOT 5

library(lme4)
Loading required package: Matrix

Attaching package: 'Matrix'
The following objects are masked from 'package:tidyr':

    expand, pack, unpack
library(glmmTMB)
Warning in checkDepPackageVersion(dep_pkg = "TMB"): Package version inconsistency detected.
glmmTMB was built with TMB version 1.9.1
Current TMB version is 1.9.2
Please re-install glmmTMB from source or restore original 'TMB' package (see '?reinstalling' for more information)
library(effects)
Loading required package: carData
lattice theme set by effectsTheme()
See ?effectsTheme for details.
m1 <- glm(formula = feeding~temp+day_of_experiment+infected+total_alive, family = "poisson", data = behavior)
m1

Call:  glm(formula = feeding ~ temp + day_of_experiment + infected + 
    total_alive, family = "poisson", data = behavior)

Coefficients:
      (Intercept)             temp30             temp34             temp37  
        -1.934153          -0.371031           0.581659           1.585467  
           temp40  day_of_experiment          infected1        total_alive  
         2.378653          -0.004843           0.123934           0.097811  

Degrees of Freedom: 1279 Total (i.e. Null);  1272 Residual
  (728 observations deleted due to missingness)
Null Deviance:      2710 
Residual Deviance: 1215     AIC: 3005
plot(allEffects(m1)) 

I think this model is a cool way to look at the different effect plots with feeding. It helps me realize that there is an interesting relationship between feeding and temperature and then feeding and infection status.