library(dplyr)
library(lubridate)
library(ggplot2)
gg_reference <- function(dataset) {
dataset %>%
ggplot(aes(x = Datetime, y = MEDI, color = Id)) +
geom_line(linewidth = 1) +
geom_line(aes(y = Reference), color = "black", size = 0.25, linetype = "dashed") +
theme_minimal() + facet_wrap(~ Id, scales = "free_y")
}
#in this example, each data point is its own reference
sample.data.environment %>%
data2reference() %>%
gg_reference()
#in this example, the first day of each ID is the reference for the other days
#this requires grouping of the Data by Day, which is then specified in across.id
#also, shift.start needs to be set to TRUE, to shift the reference data to the
#start of the groupings
sample.data.environment %>% group_by(Id, Day = as_date(Datetime)) %>%
data2reference(
filter.expression.reference = as_date(Datetime) == min(as_date(Datetime)),
shift.start = TRUE,
across.id = "Day") %>%
gg_reference()
#in this example, the Environment Data will be used as a reference
sample.data.environment %>%
data2reference(
filter.expression.reference = Id == "Environment",
across.id = TRUE) %>%
gg_reference()
Run the code above in your browser using DataLab