在一张图上添加多条线(excel 中的系列);在 RStudio 中计算响应和平均值

Add multiple lines on one graph (series in excel); count responses and average in RStudio

我试过这个代码:

ggplot(data = Master_Data) +
  geom_line(mapping = aes(
    x = fct_inorder(Gate),
    y = c(Correct),
    group = 1),
  stat = 'identity') +
  facet_wrap( ~ Condition, nrow = 2)

但它不计算“门”的平均正确响应;我无法获得两条线路(一条用于 AO,一条用于 AV)

这是我试图从 excel 复制到 R 的图表:

这是我在 RStudio 中上传的电子表格的一小部分示例:

Participant Condition Gate Sound Target Response Correct
VS0005  Clean   POD AV  Baby    baby    1
VS0005  Clean   Gate 1  AV  Sandwich    sandal  0
VS0005  Clean   Gate 2  AV  Rooster ruby    0
VS0005  Clean   Gate 3  AV  Puppy   puppy   1
VS0005  Clean   Full    AV  Peacock pizza   0
VS0005  Clean   POD AO  Banjo   banjo   1
VS0005  Clean   Gate 1  AO  Ferret  fairy   0
VS0005  Clean   Gate 2  AO  Carriage    carrot  0
VS0005  Clean   Gate 3  AO  Marble  marble  1
VS0005  Clean   Full    AO  Pasta   puzzle  0
VS0006  Clean   POD AV  Baby    baby    1
VS0006  Clean   Gate 1  AV  Sandwich    sandal  0
VS0006  Clean   Gate 2  AV  Rooster ruby    0
VS0006  Clean   Gate 3  AV  Puppy   puppy   1
VS0006  Clean   Full    AV  Peacock pizza   0
VS0006  Clean   POD AO  Banjo   banjo   1
VS0006  Clean   Gate 1  AO  Ferret  fairy   0
VS0006  Clean   Gate 2  AO  Carriage    carrot  0
VS0006  Clean   Gate 3  AO  Marble  marble  1
VS0006  Clean   Full    AO  Pasta   puzzle  0
VS0007  Degraded    POD AV  Baby    baby    1
VS0007  Degraded    Gate 1  AV  Sandwich    sandal  0
VS0007  Degraded    Gate 2  AV  Rooster ruby    0
VS0007  Degraded    Gate 3  AV  Puppy   puppy   1
VS0007  Degraded    Full    AV  Peacock pizza   0
VS0007  Degraded    POD AO  Banjo   banjo   1
VS0007  Degraded    Gate 1  AO  Ferret  fairy   0
VS0007  Degraded    Gate 2  AO  Carriage    carrot  0
VS0007  Degraded    Gate 3  AO  Marble  marble  1
VS0007  Degraded    Full    AO  Pasta   puzzle  0
VS0008  Degraded    POD AV  Baby    baby    1
VS0008  Degraded    Gate 1  AV  Sandwich    sandal  0
VS0008  Degraded    Gate 2  AV  Rooster ruby    0
VS0008  Degraded    Gate 1  AV  Puppy   puppy   1
VS0008  Degraded    Full    AV  Peacock pizza   0
VS0008  Degraded    POD AO  Banjo   banjo   1
VS0008  Degraded    Gate 1  AO  Ferret  fairy   0
VS0008  Degraded    Gate 2  AO  Carriage    carrot  0
VS0008  Degraded    Gate 3  AO  Marble  marble  1
VS0008  Degraded    Full    AO  Pasta   puzzle  0

我希望这样的东西能奏效。

library(ggplot2); library(dplyr)
Master_Data %>%
  group_by(Condition, Gate = fct_inorder(Gate), Sound) %>%
  summarize(mean = mean(Correct),
            sd = sd(Correct), .groups = "drop") %>%
  ggplot(aes(x = Gate, y = mean, color = Sound, group = Sound)) +
  geom_line() +
  geom_errorbar(aes(ymin = mean - sd, ymax = mean + sd)) +
  facet_wrap(~Condition) +
  theme_minimal()

对于数据样本来说,它看起来很糟糕,因为大多数情况下只有一个观察值。应该看起来更像包含更多数据的 excel 图表。