library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.2
## ✔ ggplot2   3.5.2     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data <- Assignment3
colnames(data)<- c("Time", "M1R1", "M1R2", "M1R3", "M2R1", "M2R2", "M2R3", "M3R1", "M3R2", "M3R3")

data2 <- data %>%
  rowwise() %>%
  mutate(M1=mean(c(M1R1, M1R2, M1R3))) %>%
  mutate(M1sd=sd(c(M1R1, M1R2, M1R3))) %>%
  mutate(M2=mean(c(M2R1, M2R2, M2R3))) %>%
  mutate(M2sd=sd(c(M2R1, M2R2, M2R3))) %>%
  mutate(M3=mean(c(M3R1, M3R2, M3R3))) %>%
  mutate(M3sd=sd(c(M3R1, M3R2, M3R3)))

data_long <- data2[, -c(2:10, 12, 14, 16)]
data_long <- data_long %>%
  gather("Microbe", "log", -"Time")

M1sd <- as.data.frame(data2[, 12])
colnames(M1sd) <- "sd"
M2sd <- as.data.frame(data2[, 14])
colnames(M2sd) <- "sd"
M3sd <- as.data.frame(data2[, 16])
colnames(M3sd) <- "sd"
sd <- rbind(M1sd, M2sd, M3sd)
data_long <- cbind(data_long, sd)
theme_set(theme_bw())
ggplot(data2, aes(x=Time,)) +
  geom_line(aes(y=M1), color="blue") +
  geom_line(aes(y=M2), color="red") +
  geom_line(aes(y=M3), color="green") +
  geom_errorbar(aes(ymin = M1-M1sd, ymax = M1+M1sd), width= 0.5) +
  geom_errorbar(aes(ymin = M2-M2sd, ymax = M2+M2sd), width= 0.5) +
  geom_errorbar(aes(ymin = M3-M3sd, ymax = M3+M3sd), width= 0.5) +
  geom_point(aes(y=M1), color="blue") +
  geom_point(aes(y=M2), color="red") +
  geom_point(aes(y=M3), color="green") +
  labs(y= "log No. of Cells") +
  labs(x= "Time (hrs)")