-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-time-series.R
39 lines (31 loc) · 1.16 KB
/
create-time-series.R
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
# Create a time series of a single variable at a site
site <- "TMP" # change this to e.g. "CRC_W" if you want a particular plot
variable <- "sapflow_2.5cm" #sapflow_5cm
# Construct a "regular expression" to find the files we want: in this case,
# CSV files starting with the site code above
pat <- paste0("^", site, ".*csv$")
# Get the names of the files we need. Note this assumes that your
# working directory is the main directory of the L1 data
files <- list.files("./TMP_2024/", pattern = pat, recursive = TRUE, full.names = TRUE)
# Helper function to read the files and filter to just the variable we want
# We use readr::read_csv for easy timestamp handling
library(readr)
f <- function(f) {
message("Reading ", basename(f))
x <- read_csv(f, col_types = "ccTccccdccii")
x[x$research_name == variable,]
}
# Read the files
dat <- lapply(files, f)
dat <- do.call("rbind", dat)
#"dataframe of variable name" <- dat
sap2.5 <- dat
#sap5 <- dat
# Plot the data
library(ggplot2)
p <- ggplot(dat, aes(TIMESTAMP, Value, color = Sensor_ID)) +
geom_line() +
facet_grid(Plot~.) +
ggtitle(paste(site, variable, paste0("(n=", nrow(dat), ")")))
print(p)
# All done!