Group 3 tutorial week 3
{data(PlantGrowth)}
summary (PlantGrowth)
## weight group
## Min. :3.590 ctrl:10
## 1st Qu.:4.550 trt1:10
## Median :5.155 trt2:10
## Mean :5.073
## 3rd Qu.:5.530
## Max. :6.310
head (PlantGrowth)
## weight group
## 1 4.17 ctrl
## 2 5.58 ctrl
## 3 5.18 ctrl
## 4 6.11 ctrl
## 5 4.50 ctrl
## 6 4.61 ctrl
str(PlantGrowth)
## 'data.frame': 30 obs. of 2 variables:
## $ weight: num 4.17 5.58 5.18 6.11 4.5 4.61 5.17 4.53 5.33 5.14 ...
## $ group : Factor w/ 3 levels "ctrl","trt1",..: 1 1 1 1 1 1 1 1 1 1 ...
boxplot(PlantGrowth$weight ~ PlantGrowth$group,
ylab = "Weight/g",
xlab = "Treatment used")

library(ggplot2)
library(ggplot2)
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
# Using dplyr functions
Plantgrowth_summary <-
PlantGrowth %>%
group_by(group) %>%
summarise(count = n(),
mean = mean(weight, na.rm = TRUE),
ssd = sd(weight, na.rm = TRUE)) %>%
mutate(se = ssd / sqrt(count),
lower_ci = mean - qt(1 - (0.05 / 2), count - 1) * se,
upper_ci = mean + qt(1 - (0.05 / 2), count - 1) * se)
# Nice table output
knitr::kable(Plantgrowth_summary)
| ctrl |
10 |
5.032 |
0.5830914 |
0.1843897 |
4.614882 |
5.449118 |
| trt1 |
10 |
4.661 |
0.7936757 |
0.2509823 |
4.093239 |
5.228761 |
| trt2 |
10 |
5.526 |
0.4425733 |
0.1399540 |
5.209402 |
5.842598 |
Plantgrowth_summary %>% ggplot() +
geom_point(aes(x = group, y = mean,
colour = group),
size = 3) +
geom_errorbar(aes(x = group,
ymin = lower_ci,
ymax = upper_ci,
colour = group),
width = 0.2, size = 1) +
labs(x = "Treatment used", y = "Weight (g)",) +
scale_colour_manual(values = c("darkorange",
"purple",
"cyan4")) +
theme_minimal() +
theme(legend.position = "none")
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

#Treatment 2 has the highest average growth