analysis.R
This R script should contain your analysis and be saved in the root directory as:
analysis.R
Your script should contain:
## @knitr analysis-setup
library(dplyr)
library(ggplot2)
<- readr::read_csv(here::here("data",
individual "individual.csv")) %>%
select(stem_diameter, height, growth_form)
## @knitr analysis-filter-data
<- individual %>%
analysis_df filter(!is.na(growth_form), growth_form != "liana")
## @knitr analysis-set-factor-levels
<- table(analysis_df$growth_form) %>%
gf_levels sort() %>%
names()
<- analysis_df %>%
analysis_df mutate(growth_form = factor(growth_form,
levels = gf_levels))
## @knitr analysis-fig1-barplot
%>%
analysis_df ggplot(aes(y = growth_form, colour = growth_form,
fill = growth_form)) +
geom_bar(alpha = 0.5, show.legend = FALSE)
## @knitr analysis-fig2-violinplots
%>%
analysis_df ::pivot_longer(cols = c(stem_diameter, height),
tidyrnames_to = "var",
values_to = "value") %>%
ggplot(aes(x = log(value), y = growth_form,
colour = growth_form, fill = growth_form)) +
geom_violin(alpha = 0.5, trim = TRUE, show.legend = FALSE) +
geom_boxplot(alpha = 0.7, show.legend = FALSE) +
facet_grid(~var)
## @knitr analysis-lm-overall
<- lm(log(stem_diameter) ~ log(height),
lm_overall
analysis_df)%>%
lm_overall ::glance()
broom%>%
lm_overall ::tidy()
broom
## @knitr analysis-lm-fig3-overall
%>%
analysis_df ggplot(aes(x = log(height), y = log(stem_diameter))) +
geom_point(alpha = 0.2) +
geom_smooth(method = "lm")
## @knitr analysis-lm-growth
<- lm(log(stem_diameter) ~ log(height) * growth_form,
lm_growth
analysis_df)%>%
lm_growth ::glance()
broom%>%
lm_growth ::tidy()
broom
## @knitr analysis-lm-fig4-growth
%>%
analysis_df ggplot(aes(x = log(height), y = log(stem_diameter),
colour = growth_form)) +
geom_point(alpha = 0.1) +
geom_smooth(method = "lm")