Dragons analysis

Challenge: Your challenge is to make the data tidy (long format) and to create a boxplot for each species showing the effect of the spices on plume size, so you can answer the questions: Which spice triggers the most fiery reaction And the least?

However, you find out that your field assistant was a bit careless during data collection, and let slip many mistakes which you will need to correct.

The fourth treatment wasn’t paprika at all, it was turmeric. There was a calibration error with the measuring device for the tabasco trial, but only for the Hungarian Horntail species. All measurements are 30 cm higher than they should be. The lengths are given in centimeters, but really it would make sense to convert them to meters.

setwd("D:\\R-tutoriales ECOLOGY\\Basic data manipulation")

library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.1
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.3.1

Dataset structure

dragon <- read.csv("dragons.csv")
head(dragon)
##   dragon.ID            species tabasco jalapeno wasabi paprika
## 1         1 hungarian_horntail     124      100     45      25
## 2         4 hungarian_horntail     156      110     47      30
## 3         7 hungarian_horntail     147       90     55      25
## 4        10 hungarian_horntail     138      136     47      23
## 5        13 hungarian_horntail     154      124     53      23
## 6        16 hungarian_horntail     110       92     48      32
str(dragon)
## 'data.frame':    60 obs. of  6 variables:
##  $ dragon.ID: int  1 4 7 10 13 16 19 22 25 28 ...
##  $ species  : chr  "hungarian_horntail" "hungarian_horntail" "hungarian_horntail" "hungarian_horntail" ...
##  $ tabasco  : int  124 156 147 138 154 110 133 150 149 153 ...
##  $ jalapeno : int  100 110 90 136 124 92 127 127 138 132 ...
##  $ wasabi   : int  45 47 55 47 53 48 84 51 54 51 ...
##  $ paprika  : int  25 30 25 23 23 32 34 30 25 25 ...

Corrections to the dataframe

First I substitute the column name “paprika” with “turmeric”, then I replace the value of the Hungarian horntail with calibration error, substracting 30 cm to each individual of the specie, or the tabasco treatment. Finally, I created a long table with the treatment, and transform the lenght from centimeters (cm) to meters (m).

dragon <- rename(dragon, turmeric = paprika)
dragon[dragon$species == "hungarian_horntail",]$tabasco - 30
##  [1]  94 126 117 108 124  80 103 120 119 123  82  92 117 135 134 118 119 121  91
## [20]  87
dragon_long <- gather(dragon, spices, lenght, c(tabasco, jalapeno, wasabi, turmeric))
dragon_long <- mutate(dragon_long, lenght_m = round(lenght/100, digits = 2))
head(dragon_long)
##   dragon.ID            species  spices lenght lenght_m
## 1         1 hungarian_horntail tabasco    124     1.24
## 2         4 hungarian_horntail tabasco    156     1.56
## 3         7 hungarian_horntail tabasco    147     1.47
## 4        10 hungarian_horntail tabasco    138     1.38
## 5        13 hungarian_horntail tabasco    154     1.54
## 6        16 hungarian_horntail tabasco    110     1.10

Plots and analysis

Acording to the graphical analysis the jalapeno has more effect in plume growth than the other spices. Otherwise, the turmeric has less effect in this variable.

This was fun!