我有6个处理组(对照,pH7,pH8,pH9,pH10,pH11),分别来自6个不同的样品(1、2、3、4、5、6),并测量变量-od
`data.frame': 288 obs. of 3 variables:
$ od : num 0.086 0.086 0.085 0.086 0.093 0.087 0.087 0.087 0.089 0.094 ...
$ sample: Factor w/ 6 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
$ medium: Factor w/ 6 levels "Control","pH10",..: 1 1 1 1 1 1 1 1 4 4 ...
我希望x轴代表所有处理组和每个样品的pH平均值图上的点 我该如何生成与此图相似的图:
样本数据。
structure(list(od = c(0.086, 0.086, 0.085, 0.086, 0.093, 0.087, 0.087, 0.087, 0.089, 0.094, 0.087, 0.088, 0.09, 0.088, 0.087, 0.088, 0.086, 0.087, 0.095, 0.096), sample = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L ), medium = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), .Label = c("Control", "pH10", "pH11", "pH7", "pH8", "pH9"), class = "factor")), row.names = c(NA, 20L), class = "data.frame")
答案 0 :(得分:0)
好吧,这可能还不太正确,但是我将其发布为答案,并根据更多信息进行编辑(没有完整的数据,只有一张照片就有点棘手了!)。
看起来(在照片中)每个“样本”都有一个数据点,该数据点必须是该“样本”(天)(处理)的“ od”的“ od”的平均值?
因此,我汇总了数据,以便为我提供每个样本日每个治疗组的平均费用:
#if you do not have the following packages then install.packages("tidyverse")
library(ggplot2)
library(tidyverse)
### REPLACE 'df' below with your dataframe name
df_summary <- df %>%
group_by(sample, medium) %>%
summarise(od_mean = mean(od))
head(df_summary)
现在,我以mean_od
作为y的值,以sample
绘制x的值,并用medium
用colour = medium
分开它们:
plot <- ggplot(df_summary, aes(x = sample, y = od_mean, colour = medium))+
geom_point()+ #add points to the plot
geom_smooth()+ #add a smoother
xlab("Day")+ #change axis lables
ylab("Bacterial Density")
plot
让我知道这是否满足您的需求。