-1

This is my data:

structure(list(Time = c(0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 
18L), Volume.1 = c(14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L), CO21 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Volume2 = c(13.5, 
13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5), CO22 = c(0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Volume3 = c(13.5, 13.5, 
13.5, 13.5, 13, 12.5, 12.5, 12, 12, 11.5), CO23 = c(0, 0, 0, 
0, 0.5, 1, 1, 1.5, 1.5, 2), Volume4 = c(13.5, 13.5, 13, 12.5, 
12, 11, 9, 7.5, 5.5, 4.5), CO24 = c(0, 0, 0.05, 1, 1.5, 2.5, 
4.5, 6, 8, 9)), row.names = c(NA, 10L), class = "data.frame")

This is data for yeast fermentation for a bio lab. We were told to use graphing software to plot the data. I need to make a graph that shows the difference in levels over time of CO2 production per tube. Tube 1 = Volume1+CO2, Tube 2 = Volume2+CO22, etc. I'm very new to R and am not sure how to proceed.

  • 1
    Read [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – markus Feb 14 '20 at 20:13
  • Do `dput(YourDataFrame[1:10,])` and post the output of that here. – Georgery Feb 14 '20 at 20:13
  • 3
    I'd recommend starting with a good tutorial—the `ggplot` docs link to several—to try making whatever type of chart you want (you haven't specified). Then if you have specific problems, come back with those – camille Feb 14 '20 at 20:27
  • What are you trying to plot, and how? You need to figure that out first, then see if you can't find examples of it already, such as [here](https://r4ds.had.co.nz/data-visualisation.html) – camille Feb 14 '20 at 22:07

1 Answers1

1

Maybe this is what you are looking for? Although, the co2 levels don't really change much across time with each tube so maybe I'm not understanding what you are attempting to graph.

library(tidyverse)

df <- data.frame(Time = c(0L, 2L, 4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L), Volume1 = c(14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L), CO21 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Volume2 = c(13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5), CO22 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Volume3 = c(13.5, 13.5, 13.5, 13.5, 13, 12.5, 12.5, 12, 12, 11.5), CO23 = c(0, 0, 0, 0, 0.5, 1, 1, 1.5, 1.5, 2), Volume4 = c(13.5, 13.5, 13, 12.5, 12, 11, 9, 7.5, 5.5, 4.5), CO24 = c(0, 0, 0.05, 1, 1.5, 2.5, 4.5, 6, 8, 9))

df1 <-
  df %>%
  pivot_longer(cols = -Time) %>%
  mutate(name = str_replace(name, "(\\d)$", ",\\1")) %>%
  separate(name, c("name", "tube")) %>%
  group_by(Time, tube) %>%
  summarize(co2 = sum(value)) 

ggplot(df1, aes(x = Time, y = co2, color = tube)) + 
  geom_line() +
  geom_point()