####Load Packages#### library(readr) library(MuMIn) library(tidyverse) library(cowplot) ####Import .csv#### RangeFilling <- read_csv("RangeFillingData.csv") ####Reorder Factors#### RangeFilling$Lecty<-factor(RangeFilling$Lecty, levels = c("Polylectic", "Oligolectic","No Lectic Status")) RangeFilling$Overwintering<-factor(RangeFilling$Overwintering, levels = c("Prepupa", "Adult within cocoon","Adult (female only)")) ####Log range filling percentage#### RangeFilling$LogPercent <- log(df$Percent) ####Run Model#### options(na.action = "na.fail") model <- lm(LogPercent ~ Habitat.Breadth + Lecty + Overwintering, data = RangeFilling) summary(model) model.dredge <- dredge(model, rank = "AICc") head(model.dredge) bestmodel <- get.models(model.dredge, 1)[[1]] summary(bestmodel) ####Plot Model#### a<-ggplot(RangeFilling, aes(x = Lecty, y = LogPercent))+ geom_boxplot()+ theme_bw()+ labs(x = "Lecty", y = "log(Climate envelope\n filled (%))") b<-ggplot(RangeFilling, aes(x = Overwintering, y = LogPercent))+ geom_boxplot()+ theme_bw()+ labs(x = "Overwintering Stage", y = "log(Climate envelope\n filled (%))") c<-ggplot(RangeFilling, aes(x = Habitat.Breadth, y = LogPercent))+ geom_point()+ geom_smooth(method="lm")+ theme_bw()+ labs(x = "Habitat Breadth", y = "log(Climate envelope\n filled (%))") plot_grid(a,b,c, ncol = 1)