-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path2_RtutorialChina.Rmd
More file actions
141 lines (111 loc) · 4.94 KB
/
2_RtutorialChina.Rmd
File metadata and controls
141 lines (111 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
title: "R tutorial China: Exploring the data"
author: "Julia Chacón"
date: "20/2/2020"
output: html_document
---
<style>
p.caption {
font-size: 0.8em;
}
</style>
```{r, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message = FALSE,
warning = FALSE
)
```
```{r Call the libraries, include=FALSE}
library("tidyverse")
library("dataDownloader")
library("DBI")
library("vegan")
library("ggvegan")
library("patchwork")
```
```{r Read cover and composition data, include=FALSE}
#check data are downloaded
if(!fs::file_exists("traits/data/PFTC1.2_China_2015_2016_ChemicalTraits.csv")){
stop("Need to download data first - see 1_RtutorialChina.Rmd")
}
source("hidden/start_here.R")
```
```{r Read trait data, include=FALSE}
traitsLeaf <- read_csv(file = "traits/data/PFTC1.2_China_2015_2016_LeafTraits.csv")
traitsChem <- read_csv(file = "traits/data/PFTC1.2_China_2015_2016_ChemicalTraits.csv")
```
# TRANSPLANT EXPERIMENT GONGGA MOUNTAIN (CHINA)
## 6. Exploring how the data are organized
### Cover and composition data
`cover_thin` is an object that contains community data (cover data and composition of each turf and treatment).
Explore the columns names in `cover_thin`, `head()` is more informative. Use whatever you prefer:
```{r Exploring how the data are organized, eval=FALSE}
colnames(cover_thin)
head(cover_thin)
```
cover is a summary of the total cover of each species in `cover_thin`
Explore the columns names in cover:
```{r Exploring how the data are organized2, eval = FALSE}
colnames(cover)
```
Check the dimensions of cover_thin and cover:
```{r Exploring how the data are organized3, eval = TRUE, echo=TRUE}
dim(cover_thin)
dim(cover)
```
Check number of Sites:
```{r Exploring how the data are organized4, eval=TRUE}
levels(cover_thin$originSiteID)
```
Check blocks per elevation/site:
```{r Exploring how the data are organized5, eval=FALSE}
unique(cover_thin$originBlockID)
```
Check treatments:
```{r Exploring how the data are organized6, eval=TRUE}
levels(cover_thin$TTtreat)
```
Exploring the levels of each factor, allows to get an idea of the experimental setup. For example, number of sites, blocks per site, Treatments names, and how are the variables stored in cover_thin. Just to remember, there are four study sites that contains an in situ warming experiments using OTCs and reciprocal community transplantation experiments (i.e., warming and cooling) between all pairs of neighbouring sites along the gradient. There are seven blocks at each site. Within each of the seven blocks at each site, plots were randomly designated to SIX different experimental treatments. You can get a better idea reading the [README file](https://github.com/richardjtelford/transplant/blob/master/ReadMe.md) of the China data.
### Trait data
Again, we suggest starting exploring the data sets of traits, asking for the names of the columns, the levels of each factor, and dimensions.
```{r Trait data, eval=FALSE}
colnames(traitsLeaf)
colnames(traitsChem)
```
Explore a bit the levels of each factor, and the variable names. They are coded differently to cover_thin.
```{r Trait data2, eval=TRUE}
unique(traitsLeaf$Elevation)
```
```{r Trait data3, eval=TRUE}
unique(traitsLeaf$Treatment)
```
So, one important thing to do before exploring/analysing the data is to follow the same coding in the treatment levels for cover and traits data.
In the traits data, Treatment has 8 levels, the extra one is LOCAL that refers to the traits that were measured outside the experimental plots. So no treatment there.
In the cover data, there are 7 levels: "control" "local" "warm1" "cool1" "warm3" "cool3" "OTC", and local is referred to the local transplants. So...the coding is really confusing. We want to change it, right?
### Rename the treatment levels
Let´s rename the levels of Treatment:
```{r Rename the treatment levels, eval=TRUE}
traitsLeaf <- traitsLeaf %>%
mutate(Treatment = recode(Treatment,
"C" = "control", "0" = "local", "1" = "warm1",
"2" = "cool1", "3" = "warm3", "4" = "cool3",
"LOCAL" = "outexp", "OTC" = "OTC")) %>%
mutate(Treatment = factor(Treatment,
levels = c("local", "control", "warm1", "cool1", "warm3", "cool3", "OTC", "outexp")))
traitsChem <- traitsChem %>%
mutate(Treatment = recode(Treatment,
"C" = "control","0" = "local", "1" = "warm1",
"2" = "cool1", "3" = "warm3", "4" = "cool3",
"LOCAL" = "outexp", "OTC" = "OTC")) %>%
mutate(Treatment = factor(Treatment,
levels = c("local", "control", "warm1", "cool1", "warm3", "cool3", "OTC", "outexp")))
```
Check the levels now:
```{r Rename the treatment levels2, eval=TRUE}
levels(traitsLeaf$Treatment)
```
```{r Rename the treatment levels3, eval=TRUE}
levels(cover_thin$TTtreat)
```