-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_targets_full.R
More file actions
44 lines (41 loc) · 1.05 KB
/
Copy path_targets_full.R
File metadata and controls
44 lines (41 loc) · 1.05 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
library(targets)
# Global options
tar_option_set(
packages = c("dplyr", "ggplot2", "readr")
)
list(
#Simulate or load raw data
tar_target(
raw_data,
tibble::tibble(
date = rep(seq.Date(as.Date("2023-01-01"), as.Date("2023-01-10"), by = "day"), each = 3),
species = rep(c("fox", "deer", "rabbit"), times = 10),
count = sample(1:10, 30, replace = TRUE)
)
),
#filter for a specific species
tar_target(
fox_data,
raw_data %>% filter(species == "fox")
),
#Summarize counts by date
tar_target(
daily_fox_counts,
fox_data %>%
group_by(date) %>%
summarise(total = sum(count), .groups = "drop")
),
#Plot the daily fox counts
tar_target(
fox_plot,
{
p <- ggplot(daily_fox_counts, aes(x = date, y = total)) +
geom_line(color = "darkorange", size = 1) +
geom_point() +
labs(title = "Daily Fox Counts", x = "Date", y = "Count") +
theme_minimal()
ggsave("fox_counts.png", plot = p, width = 6, height = 4)
"fox_counts.png"
}
)
)