@@ -5,17 +5,6 @@ date: "`r Sys.Date()`"
55output : html_document
66---
77
8- ``` {r setup}
9- library(traits)
10- knitr::opts_chunk$set(echo = FALSE, cache = TRUE)
11- library(ggplot2)
12- library(ggthemes)
13- library(GGally)
14- theme_set(theme_bw())
15- library(dplyr)
16- ```
17-
18-
198## TERRA Ref Trait Database
209
2110The TERRA Ref program uses the BETYdb database and web application software to store plant and plot level trait data.
@@ -104,21 +93,72 @@ First, lets construct a query by putting together a URL.
10493
10594What do you see? Do you think that this is all of the records? What happens if you add ` &limit=none ` ?
10695
107- ### Using the R traits package to query the database
96+ ## Using the R traits package to query the database
10897
10998The rOpenSci traits package makes it easier to query the TERRA REF trait database, or any database that uses BETYdb software.
11099
100+ First, make sure we have the latest version
101+
102+ ``` {r install_traits, echo=FALSE}
103+ if(packageVersion("traits") == '0.2.0'){
104+ devtools::install_github('ropensci/traits')
105+ }
106+ ```
107+
108+
109+ ``` {r setup}
110+ library(traits)
111+ knitr::opts_chunk$set(echo = FALSE, cache = TRUE)
112+ library(ggplot2)
113+ library(ggthemes)
114+ theme_set(theme_bw())
115+ library(dplyr)
116+ ```
117+
118+
119+
120+ ``` {r writing-key}
121+ # This should be done once with the key sent to you in your email
122+ # writeLines('abcdefg_rest_of_key_sent_in_email',
123+ # con = '~/.betykey')
124+
125+ # Example with the public key:
126+ writeLines('9999999999999999999999999999999999999999',
127+ con = '~/.betykey_public')
128+ ```
111129``` {r traits}
130+ terraref_test_url <- "https://terraref.ncsa.illinois.edu/bety-test/"
131+
132+ betykey <- readLines('~/.betykey_public', warn = FALSE)
112133
113- terraref_betyurl <- "https://terraref.ncsa.illinois.edu/bety/"
114- betykey <- readLines('~/.betykey', warn = FALSE)
115134```
116135
117- ``` {r}
118- sorghum_all <- betydb_search(query = 'Sorghum',
119- betyurl = terraref_betyurl,
120- key = betykey)
136+ ``` {r simulated-LAI}
137+ sorghum_lai <- betydb_query(table = 'search',
138+ trait = "LAI",
139+ api_version = 'beta',
140+ limit = 5000,
141+ betyurl = terraref_test_url,
142+ key = betykey)
143+
144+ #traits <- betydb_query(table = "traits",
145+ # api_version = 'beta',
146+ # limit = 5000,
147+ # betyurl = terraref_test_url,
148+ # key = betykey)
149+
150+
121151
122152```
123153
154+ ``` {r}
155+
156+ ggplot(data = sorghum_lai) +
157+ geom_smooth(aes(x = lubridate::yday(lubridate::ymd_hms(raw_date)), y = mean, color = as.factor(lubridate::year(lubridate::ymd_hms(raw_date)))), span = 0.5) +
158+ # scale_x_datetime(date_breaks = '6 months', date_labels = "%b %Y") +
159+ ylim(c(0,6)) +
160+ ylab("Day of Year") + xlab("Leaf Area Index") +
161+ labs(color='Year')
162+
163+ ```
124164
0 commit comments