# Convert Treatment and Type to factors (if not already)
CO2$Treatment <- as.factor(CO2$Treatment) # nolint: object_name_linter.
CO2$Type <- as.factor(CO2$Type) # nolint: object_name_linter.Test R Markdown
Data preparation
Uptake by Plant Type and Treatment
library(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
# Summarize mean uptake by Type and Treatment
CO2 |>
group_by(Type, Treatment) |>
summarise(mean_uptake = mean(uptake), .groups = "drop")# A tibble: 4 × 3
Type Treatment mean_uptake
<fct> <fct> <dbl>
1 Quebec nonchilled 35.3
2 Quebec chilled 31.8
3 Mississippi nonchilled 26.0
4 Mississippi chilled 15.8
Visualization: Uptake by Concentration
library(ggplot2)
ggplot(CO2, aes(x = conc, y = uptake, color = Treatment, shape = Type)) +
geom_point() +
geom_smooth(formula = "y ~ x", method = "lm", se = FALSE) +
labs(
title = "CO2 Uptake vs. Concentration",
x = "CO2 Concentration (mL/L)",
y = "CO2 Uptake (umol/m^2 sec)",
color = "Treatment",
shape = "Plant Type"
) +
theme_minimal()
Visualization: Uptake Distribution by Plant
ggplot(CO2, aes(x = Plant, y = uptake, fill = Treatment)) +
geom_boxplot() +
labs(
title = "CO2 Uptake Distribution by Plant",
x = "Plant",
y = "CO2 Uptake (umol/m^2 sec)",
fill = "Treatment"
) +
theme_minimal()