Skip to content

Commit 7fcbcb9

Browse files
committedSep 29, 2024·
Create growth_plot.R
1 parent 45ceb05 commit 7fcbcb9

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
 

‎growth_plot.R

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Plot database growth over time
2+
# BBL 2024-09-30
3+
4+
if(basename(getwd()) != "srdb") stop("Working directory must be srdb/")
5+
6+
library(ggplot2)
7+
theme_set(theme_bw())
8+
library(scales)
9+
library(dplyr)
10+
library(tidyr)
11+
12+
read.csv("srdb-data.csv") %>%
13+
mutate(Y = as.integer(substr(Entry_date, 1, 4))) ->
14+
x
15+
16+
x %>%
17+
group_by(Y) %>%
18+
summarise(N = n()) %>%
19+
mutate(type = "Total records") ->
20+
x1
21+
22+
x %>%
23+
filter(Manipulation == "None", !is.na(Rs_annual)) %>%
24+
group_by(Y) %>%
25+
summarise(N = n()) %>%
26+
mutate(type = "Rs_annual, no manipulation") ->
27+
x2
28+
29+
x %>%
30+
filter(Manipulation == "None", !is.na(Rh_annual)) %>%
31+
group_by(Y) %>%
32+
summarise(N = n()) %>%
33+
mutate(type = "Rh_annual, no manipulation") ->
34+
x3
35+
36+
x %>%
37+
filter(Manipulation == "None", !is.na(Rs_growingseason)) %>%
38+
group_by(Y) %>%
39+
summarise(N = n()) %>%
40+
mutate(type = "Rs_growingseason, no manipulation") ->
41+
x4
42+
43+
bind_rows(x1, x2, x3, x4) %>%
44+
complete(Y = 2008:2024, type, fill = list(N = 0)) %>%
45+
arrange(Y) %>%
46+
group_by(type) %>%
47+
mutate(cum_N = cumsum(N)) ->
48+
x_final
49+
50+
p <- ggplot(x_final, aes(Y, cum_N, color = type)) +
51+
geom_line(linewidth = 1) +
52+
xlab("Year of entry") + ylab("Database entries") +
53+
scale_color_discrete("") +
54+
scale_y_continuous(labels = comma) +
55+
theme(legend.position = "inside",
56+
legend.position.inside = c(0.3, 0.85),
57+
legend.background = element_blank())
58+
print(p)
59+
ggsave("R/growth_plot.png", width = 8, height = 5)

0 commit comments

Comments
 (0)
Please sign in to comment.