################################################################## # SpiceOfLife.r # Statypus Academy: Visualizing the Resistants # Course Resources: statypus.org ################################################################## # 0. THE SETUP: ENVIRONMENT & WORKING COPY # Fetch the Chapter 4 data directly from the Statypus server: load(url("https://statypus.org/files/StatypusCh4.RData")) df <- PlatypusData2 # Find the global minimum and maximum weight across ALL platypuses # This allows us to lock the scale for a true side-by-side comparison weight_limits <- range(df$WeightF, na.rm = TRUE) # Split the graphics window into 2 rows and 1 column so we can compare # Don't worry. We will reset this before we are done par(mfrow = c(2, 1)) # 1. PASS ONE: THE RAW DATA (All Ages) MaleAll <- df[df$Sex == "M", ] FemaleAll <- df[df$Sex == "F", ] boxplot(MaleAll$WeightF, FemaleAll$WeightF, horizontal = TRUE, names = c("Male", "Female"), col = c("lightblue", "lightpink"), main = "Pass 1: All Platypuses (Including Juveniles)", xlab = "Weight (kg)", ylim = weight_limits) # Force the global scale # 2. THE FILTER: REMOVING NOISE # Juveniles weigh less, which might blur the true difference between adult sexes. # We create a new "Adults Only" dataset by keeping rows where Age is NOT "J". df_adults <- df[df$Age != "J", ] # 3. PASS TWO: THE REFINED AUDIT (Adults Only) MaleAdult <- df_adults[df_adults$Sex == "M", ] FemaleAdult <- df_adults[df_adults$Sex == "F", ] boxplot(MaleAdult$WeightF, FemaleAdult$WeightF, horizontal = TRUE, names = c("Adult Male", "Adult Female"), col = c("royalblue", "hotpink"), main = "Pass 2: Adults Only", xlab = "Weight (kg)", ylim = weight_limits) # Force the exact same scale as Pass 1 # Reset the graphics window back to normal to make Bill happy par(mfrow = c(1, 1))