0

我需要得到一个图表,其中包含 4 种不同盐度下两个牡蛎种群的平均累积死亡率。

Date = c("5/29/2017","5/31/2017","6/2/2017", "5/29/2017","5/31/2017","6/2/2017","5/29/2017","5/31/2017","6/2/2017","5/29/2017","5/31/2017","6/2/2017","5/29/2017","5/31/2017 ","6/2/2017","5/29/2017 ","5/31/2017","6/2/2017", "5/29/2017","5/31/2017","6/2/2017","5/29/2017", "5/31/2017","6/2/2017")
Mortality =  c(0, 0.4, 0.5, 0.1, 0.3, 0.4, 0.2, 0.3, 0.5, 0.1, 0.2, 0.6, 0, 0.7, 0.8, 0.1, 0.6, 0.9, 0.1, 0.5, 0.9, 0.1, 0.6, 0.8)
Tank = c("1A", "1A", "1A", "1B", "1B", "1B", "5A", "5A", "5A", "5B", "5B", "5B", "1A", "1A", "1A", "1B", "1B", "1B", "5A", "5A", "5A", "5B", "5B", "5B")
Population = c("SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC") = c (SL SL SL SL SL SL SL SL SL SL SL SL LC LC LC LC LC LC LC LC LC LC LC LC)

我需要平均这两个值(例如 1A 和 1B),然后为日期绘制该值。我只想将计算累积死亡率的日期显示在 x 轴上。

我有以下在 Excel 中制作的图表,但不是我需要的。

盐度图

4

1 回答 1

1

这是我使用ggplot2和的解决方案dplyr

您可以在绘图之前使用其他包来汇总您的数据。在这里,我做了两组(1 = 1A 和 1B,2 = 其他坦克)。

只是出于好奇,您为什么不对这些数据使用 Kapplan-Meier 图?

Date = c("5/29/2017","5/31/2017","6/2/2017", "5/29/2017","5/31/2017","6/2/2017","5/29/2017","5/31/2017","6/2/2017","5/29/2017","5/31/2017","6/2/2017","5/29/2017","5/31/2017 ","6/2/2017","5/29/2017 ","5/31/2017","6/2/2017", "5/29/2017","5/31/2017","6/2/2017","5/29/2017", "5/31/2017","6/2/2017")
Mortality =  c(0, 0.4, 0.5, 0.1, 0.3, 0.4, 0.2, 0.3, 0.5, 0.1, 0.2, 0.6, 0, 0.7, 0.8, 0.1, 0.6, 0.9, 0.1, 0.5, 0.9, 0.1, 0.6, 0.8)
Tank = c("1A", "1A", "1A", "1B", "1B", "1B", "5A", "5A", "5A", "5B", "5B", "5B", "1A", "1A", "1A", "1B", "1B", "1B", "5A", "5A", "5A", "5B", "5B", "5B")
Population = c("SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "SL", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC", "LC")


df <- data.frame(Date, Mortality, Tank, Population)

library(dplyr)
library(ggplot2)

dfs <- df %>% mutate(TankGroup =  if_else(Tank %in% c('1A','1B'),1,2)) %>% 
  group_by(Date, TankGroup) %>% 
  summarise(Mortality = mean(Mortality))

ggplot(dfs, aes(x = Date, y = Mortality, group = factor(TankGroup), color = factor(TankGroup))) +
  geom_point() + geom_line() + theme_bw()
于 2017-07-20T09:10:23.990 回答