简体   繁体   English

如何在ggplot中绘制这些数据?

[英]How to plot this data in ggplot?

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.我需要制作一个图表,显示每管 CO2 产量随时间的变化水平。 Tube 1 = Volume1+CO2, Tube 2 = Volume2+CO22, etc. I'm very new to R and am not sure how to proceed. Tube 1 = Volume1+CO2,Tube 2 = Volume2+CO22 等等。我对 R 很陌生,不知道如何进行。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM