使用 ggplot2 绘制单个观察值和组均值

Plotting individual observations and group means with facets with ggplot2

我正在尝试绘制 ggplot 中具有三个受试者内变量(测试项目、框架、样本量)的研究数据。我在 x 轴上总结并绘制了测试项目,并为样本大小设置了单独的行,并使用 facet_grid 分隔两个框架条件。汇总此数据以创建受试者内 95% CI 误差线。我还想强调个别参与者的台词。到目前为止,我找到的所有建议都没有解释在对数据进行分面后如何绘制单个数据和分组数据。我尝试过的一切看起来都很乱,并且没有清楚地显示个人的 curves/lines.

有办法吗?

我考虑过按分面条件拆分数据并单独绘制,但如果有更简单的方法,我想找到它!

以下是部分数据:

human_exp1 <- structure(list(sample_size = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L,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 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L), .Label = c("category", "property"), class = "factor"), 
    test_item = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2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 4L, 4L, 4L, 4L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 
    6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
    4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L
    ), .Label = c("1", "2", "3", "4", "5", "6"), class = "factor"), 
    id = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 
    11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 
    4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 
    17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
    12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 
    6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
    19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 
    14L, 15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
    8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 
    1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
    9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L), .Label = c("1", 
    "2", "3", "4", "6", "7", "8", "9", "10", "11", "12", "13", 
    "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", 
    "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", 
    "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", 
    "44", "45", "46", "47", "48", "49", "50", "85", "86", "87", 
    "88", "89", "90", "91", "92", "93", "94", "95", "96"), class = "factor"), 
    response = c(0.75, 0.25, 0.4, 0.5, 0.3, 0.55, 0.65, 0.4, 
    0.3, 0.5, 0, 0.15, 0.65, 0.65, 0.5, 0.65, 0.8, 0.65, 0.65, 
    0.75, 0.15, 0.35, 0.6, 0.15, 0.3, 0.5, 0.1, 0.3, 0.5, 0, 
    0.25, 0.45, 0.75, 0.7, 0.45, 0.65, 0.75, 0.75, 0.3, 0.1, 
    0.25, 0.15, 0.2, 0.3, 0.35, 0.05, 0.3, 0.5, 0, 0.15, 0.5, 
    0.1, 0.35, 0.25, 0.5, 0.5, 0, 0.25, 0, 0.3, 0.1, 0.15, 0.35, 
    0.2, 0, 0.3, 0.5, 0, 0.1, 0.5, 0, 0.3, 0.1, 0.7, 0.45, 0, 
    0.25, 0, 0.35, 0.1, 0.15, 0.3, 0.1, 0, 0.2, 0.25, 0, 0.1, 
    0.5, 0, 0.15, 0.3, 0.7, 0.4, 0, 0.05, 0.1, 0.3, 0.1, 0, 0.3, 
    0.05, 0, 0.25, 0.25, 0, 0.15, 0.5, 0, 0.1, 0, 0.75, 0.6, 
    0, 0.75, 0.3, 0.9, 0.3, 0.2, 0.95, 0.6, 0.7, 0.6, 0.5, 0, 
    0, 0.5, 0.9, 0.8, 0.9, 0.75, 0.7, 0.8, 0.5, 0.25, 0.1, 0.05, 
    0, 0.65, 0.5, 0.3, 0.8, 0.5, 0, 0, 0.5, 0.4, 0.85, 0.5, 0.55, 
    0.55, 0.35, 0.3, 0.2, 0.15, 0.05, 0, 0.3, 0.15, 0.05, 0.45, 
    0.5, 0, 0, 0.5, 0.45, 0.55, 0.3, 0.35, 0.4, 0.3, 0.15, 0.2, 
    0.15, 0, 0, 0.3, 0.1, 0, 0.3, 0.5, 0, 0, 0.5, 0.35, 0.35, 
    0.25, 0.3, 0.5, 0.35, 0.05, 0.2, 0, 0, 0.05, 0.3, 0.05, 0, 
    0.3, 0.5, 0, 0, 0.5, 0, 0.55, 0, 0.3, 0.35, 0.2, 0.1, 0.2, 
    0, 0, 0, 0.3, 0.05, 0, 0.25, 0.5, 0, 0, 0.5, 0, 0.55, 0, 
    0.25, 0.5, 0.25, 0.8, 0.4, 0.75, 0.7, 0.45, 0.95, 0.85, 0.55, 
    0.7, 0.5, 0, 0.5, 0.8, 0.8, 0.95, 1, 0.8, 0.7, 1, 0.9, 0.2, 
    0.7, 0.75, 0.25, 0.7, 0.6, 1, 0.7, 0.5, 0, 1, 0.8, 0.9, 0.8, 
    0.75, 0.8, 0.85, 1, 0.25, 0.1, 0.2, 0.15, 0.25, 0.6, 0.2, 
    0, 0.45, 0.5, 0, 0.5, 0.7, 0.35, 0.45, 0.25, 0.75, 0.4, 0.2, 
    0.1, 0.15, 0.65, 0.1, 0.2, 0.55, 0.05, 0, 0.4, 0.5, 0, 0.5, 
    0.6, 0.35, 0.35, 0, 0.7, 0.45, 0, 0.1, 0.15, 0.15, 0.15, 
    0.05, 0.55, 0, 0, 0.35, 0.25, 0, 0.5, 0.55, 0.35, 0.2, 0, 
    0.8, 0.45, 0, 0.05, 0, 0.6, 0.25, 0.1, 0.5, 0, 0, 0.35, 0.25, 
    0, 0.5, 0.45, 0.35, 0.2, 0, 0.75, 0.4, 0.1, 0.9, 0.5, 0.95, 
    0.55, 0.4, 1, 0.65, 0.75, 0.6, 0.5, 0, 0.5, 0.75, 0.85, 0.95, 
    0.9, 0.6, 0.85, 0.75, 0.5, 0.5, 0.95, 0.3, 0.3, 0.55, 0.45, 
    0.35, 0.9, 0.5, 0, 0, 0.25, 0.65, 0.9, 0.25, 0.75, 0.65, 
    0.25, 0.2, 0.2, 0.1, 0.05, 0, 0.1, 0.15, 0.05, 0.4, 0.5, 
    0, 0, 0.45, 0.4, 0.55, 0.1, 0.5, 0.5, 0.2, 0.1, 0.2, 0.4, 
    0, 0, 0.1, 0.05, 0, 0.2, 0.5, 0, 0, 0.35, 0.35, 0.55, 0.1, 
    0.35, 0.4, 0.15, 0.1, 0.2, 0, 0, 0, 0.05, 0, 0, 0.2, 0.5, 
    0, 0, 0.15, 0, 0.55, 0, 0.2, 0.45, 0.15, 0.05, 0.25, 0, 0, 
    0, 0.05, 0, 0, 0.2, 0.5, 0, 0, 0.3, 0, 0.55, 0, 0.3, 0.35, 
    0.05, 0.8, 0.15, 0.8, 0.8, 0.75, 1, 0.7, 0.5, 0.95, 0.5, 
    0, 0.5, 0.9, 0.85, 1, 1, 1, 0.8, 1, 1, 0.15, 0.75, 0.8, 0.4, 
    1, 0.5, 1, 0.85, 0.5, 0, 1, 0.85, 1, 0.85, 0.9, 0.9, 0.85, 
    1, 0.1, 0, 0.25, 0.3, 0.4, 0.65, 0, 0, 0.6, 0.5, 0, 0, 0.75, 
    0.65, 0.65, 0.45, 0.7, 0.5, 0, 0.1, 0, 0.2, 0.3, 0.4, 1, 
    0, 0, 0.6, 0.5, 0, 0, 0.7, 0.35, 0.55, 0, 0.85, 0.3, 0, 0.1, 
    0, 0.25, 0.25, 0.1, 0.65, 0, 0, 0.65, 0.25, 0, 0, 0.65, 0.35, 
    0.3, 0.05, 0.85, 0.3, 0, 0.05, 0, 0.15, 0.25, 0.1, 0.5, 0, 
    0, 0.45, 0.25, 0, 0, 0.6, 0.35, 0.3, 0, 0.65, 0.25, 0, 0.95, 
    0.6, 1, 0.75, 0.65, 0.5, 0.55, 0.9, 0.8, 0.5, 0, 1, 0.9, 
    0.95, 1, 0.95, 0.5, 0.85, 0.8, 0.5, 0.55, 0.95, 0.45, 0.55, 
    0.5, 0.4, 0.35, 0.8, 0.5, 0, 0, 0.35, 0.65, 1, 0.45, 0.5, 
    0.55, 0.25, 0.15, 0.3, 0.25, 0.15, 0, 0, 0, 0, 0.35, 0.5, 
    0, 0, 0.4, 0.35, 0.5, 0.05, 0.25, 0.4, 0, 0.05, 0.2, 0.45, 
    0, 0, 0, 0, 0, 0.25, 0.5, 0, 0, 0.3, 0.35, 0.5, 0, 0, 0.35, 
    0, 0.05, 0.25, 0, 0, 0, 0, 0, 0, 0.15, 0.5, 0, 0, 0.15, 0, 
    0.5, 0, 0, 0.3, 0, 0.05, 0.25, 0, 0, 0, 0, 0, 0, 0.2, 0.5, 
    0, 0, 0.15, 0, 0.5, 0, 0, 0.35, 0)), row.names = c(NA, -684L
), class = c("tbl_df", "tbl", "data.frame"))

我用summarySEwithin总结了数据:

within <- Rmisc::summarySEwithin(data = human_exp1, measurevar = "response",
                                 withinvars = c("sample_size", "sampling_frame", "test_item"),
                                 idvar = "id")

我使用汇总数据绘制了 ggplot 中的组均值。特别是这样我就可以计算均值的 ss 内置信区间。

pd <- position_dodge(0.1) 

ggplot(within, aes(x=test_item, y=response, colour=factor(sample_size), group=factor(sample_size)))+
  geom_point(position=pd, size=5)+
  geom_line(position=pd, size = .8)+ 
  facet_grid(cols = vars(sampling_frame))+ 
  geom_errorbar(aes(ymin=response-ci, ymax=response+ci), width=1, position=pd, size=1)+
  ylim(0, 1)+
  theme_bw()+
  scale_x_discrete(
    breaks=c("1","2","3", "4", "5", "6"),
    labels=c("S1", "S2", "T1", "T2", "T3", "T4")
  )+
  # theme(legend.position = c(.9, .85))+
  labs(x = "Test Item", y = "Generalisation Response")

然后我总结了数据并按所有分组变量分组,包括 id


gd <- human %>% 
  group_by(id, test_item, sample_size, sampling_frame) %>% 
  summarise(response = mean(response))%>%
  ungroup()

gd

然后我尝试了许多不同版本的 geom_line()gd 汇总数据来添加单独的行。

如有任何帮助,我们将不胜感激。我希望单独的线在组平均线后面显示为微弱的灰色线。

这是我的受试者内分组数据

这是我尝试使用 geom_line(data = human, aes(x=test_item, y=response, group=id))

添加单行时得到的结果

这是您要找的吗?

library(dplyr)
library(ggplot2)

within %>%
  ungroup() %>%
  group_by(test_item, sample_size) %>%
  summarise(mean = mean(response), ci = sd(response)) -> smry
  
pd <- "jitter"
ggplot(within, aes(x = test_item, y = response)) +
  geom_point(aes(colour = sample_size), position = pd) +
  geom_errorbar(
    data = smry,
    mapping = aes(y = mean, ymin = mean - ci, ymax = mean + ci), 
    size = 1
  )+
  facet_grid(cols = vars(sampling_frame)) + 
  ylim(0, 1) +
  scale_x_discrete(
    breaks = c("1","2","3", "4", "5", "6"),
    labels = c("S1", "S2", "T1", "T2", "T3", "T4")
  ) +
  labs(x = "Test Item", y = "Generalisation Response") +
  theme_bw()
  # theme(legend.position = c(.9, .85))+

这是你想要的吗?我按 idsample_size 对单行进行分组以获得单行:

ggplot(within, aes(x=test_item, y=response, colour=factor(sample_size), group=factor(sample_size)))+
  geom_point(position=pd, size=5)+
  geom_line(position=pd, size = .8)+ 
  facet_grid(cols = vars(sampling_frame))+ 
  geom_errorbar(aes(ymin=response-ci, ymax=response+ci), width=1, position=pd, size=1)+
  ylim(0, 1)+
  theme_bw()+
  scale_x_discrete(
    breaks=c("1","2","3", "4", "5", "6"),
    labels=c("S1", "S2", "T1", "T2", "T3", "T4")
  )+
  # theme(legend.position = c(.9, .85))+
  labs(x = "Test Item", y = "Generalisation Response")  + 
  geom_line(data=human_exp1, alpha=0.2, color="black", aes(x=test_item, Y=response, group=interaction(id,sample_size)))