-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-exploratory-data-analysis.R
48 lines (36 loc) · 1.25 KB
/
02-exploratory-data-analysis.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
40
41
42
43
44
45
46
47
48
# Code modified from lterdatasampler package: https://lter.github.io/lterdatasampler/articles/hbr_maples_vignette.html
# Load packages -----------------------------------------------------------
library(ggplot2)
library(dplyr)
# Load data ---------------------------------------------------------------
maples <- readRDS("data/maples.rds")
# Make a boxplot by watershed -------------------------------------------------
ggplot(data = maples, aes(x = watershed, y = stem_length)) +
geom_boxplot(aes(color = watershed, shape = watershed),
alpha = 0.8,
width = 0.5) +
geom_jitter(
aes(color = watershed),
alpha = 0.5,
show.legend = FALSE,
position = position_jitter(width = 0.2, seed = 0)
) +
labs(
x = "Watershed",
y = "Stem length (millimeters)",
title = "Stem Lengths of Sugar Maple Seedlings",
subtitle = "Hubbard Brook LTER"
) +
facet_wrap(~year) +
theme_minimal()
# Summary statistics ------------------------------------------------------
maple_summary <- maples %>%
filter(!is.na(stem_length)) %>%
group_by(year, watershed) %>%
summarize(
mean_length = mean(stem_length),
median_length = median(stem_length),
sd_length = sd(stem_length),
n = n()
)
maple_summary