Skip to content

Instantly share code, notes, and snippets.

@luisDVA
Created July 28, 2015 00:43
Show Gist options
  • Save luisDVA/a9adec9e177812c12181 to your computer and use it in GitHub Desktop.
Save luisDVA/a9adec9e177812c12181 to your computer and use it in GitHub Desktop.
plotting trees pt 1
# Dependencies
if(!require(party)){
install.packages("party")
library(party)
}
if(!require(dplyr)){
install.packages("dplyr")
library(dplyr)
}
if(!require(xlsx)){
install.packages("xlsx")
library(xlsx)
}
# Download the data directly from the journal
fileURL <- "http://s3-eu-west-1.amazonaws.com/files.figshare.com/2149369/S1_File.xlsx"
# download the excel file as a binary file otherwise it won't read (at least in Windows)
download.file(fileURL,destfile = "rodentData.xlsx",mode="wb")
# read the first and only sheet in the file
OzRodents<- read.xlsx("rodentData.xlsx",1)
# rename the relevant columns
OzRodents <- OzRodents %>% rename(North.South=NS,
Body.mass=fmass,
Habitat=habopenness)
# manipulate the data to match the labels in the figure
# change decline category into a binary outcome
OzRodents <- OzRodents%>% mutate(declinecategory=ifelse(declinecategory != "none",1, 0))
OzRodents$declinecategory <- as.factor(OzRodents$declinecategory)
# change NorthSouth into factor
OzRodents <- OzRodents%>% mutate(North.South=ifelse(North.South != 1,"South", "North"))
OzRodents$North.South <- as.factor(OzRodents$North.South)
# change Habitat.openness into open vs. forest (based on the data and as described in the methods section)
OzRodents <- OzRodents%>% mutate(Habitat=ifelse(Habitat > 2,"forest", "open"))
OzRodents$Habitat <- as.factor(OzRodents$Habitat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment