当我提供 C.I 时,如何绘制置信区间。价值观

How do I plot the confidence interval when I provide the C.I. values

我不是根据实际数据绘制的,我只有一个 data.frame 列出了 x、y 值以及上下置信区间。我想绘制具有置信区间的折线图。我想绘制这样的东西:

我该怎么做?这是 data.frame:

grp   x                y                se         conf.low        conf.high
 0    0   66.27373472086  1.51067072892736 63.3124335788501 69.2350358628699
 1    0 74.2148696059611  1.40010518400934 71.4703052207858 76.9594339911364
 0 0.67 69.3077020704515  1.31170050247573    66.7364334799 71.8789706610029
 1 0.67 76.3216788839049  1.20426555957627 73.9610102692502 78.6823474985597
 0    1 70.8020441978622  1.22261128345911 68.4054132705439 73.1986751251804
 1    1 77.3593610655788  1.11440617937562 75.1748398271279 79.5438823040297
 0 1.33 72.2963863252729   1.1412866614517 70.0591724644355 74.5336001861103
 1 1.33 78.3970432472526  1.03045308168746 76.3770915601266 80.4169949343786
 0 1.67 73.8360115474536  1.06749385699758 71.7434504636362 75.9285726312711
 1 1.67 79.4661703435226 0.951785143725553 77.6004279424212  81.331912744624
 0    2 75.3303536748644  1.00766551737773 73.3550714441075 77.3056359056212
 1    2 80.5038525251965 0.885018762433004 78.7689893139698 82.2387157364231
 0 2.33 76.8246958022751 0.961651291277803 74.9396132276638 78.7097783768863
 1 2.33 81.5415347068703 0.830004991659586 79.9145125619316  83.168556851809
 0 2.67 78.3643210244558 0.930852945704656 76.5396110870919 80.1890309618197
 1 2.67 82.6106618031403 0.788216247319819 81.0655562889848 84.1557673172958
 0    3 79.8586631518665 0.918673165304013 78.0578287003509 81.6594976033822
 1    3 83.6483439848142 0.764438197615392 82.1498495318225 85.1468384378058
 0 3.33 81.3530052792773 0.924646047789058 79.5404624498965  83.165548108658
 1 3.33  84.686026166488 0.758771039041166 83.1986407942751 86.1734115387008
 0 3.67  82.892630501458 0.949415832811663 81.0315325559489 84.7537284469671
 1 3.67  85.755153262758 0.772285708885219 84.2412756798491 87.2690308456669
 0    4 84.3869726288687 0.990197010525795  82.445933140954 86.3280121167834
 1    4 86.7928354444318 0.803258225588529 85.2182438042978 88.3674270845659
 0 4.33 85.8813147562794  1.04552693252472 83.8318144647857 87.9308150477731
 1 4.33 87.8305176261057 0.849887736164329 86.1645202148295 89.4965150373818

您正在寻找 geom_ribbon。调用你的数据框 df:

ggplot(df, aes(x = x, y = y, group = factor(grp),
               color = factor(grp), fill = factor(grp))) +
    geom_ribbon(aes(ymax = conf.high, ymin = conf.low), alpha = 0.2) +
    geom_line()

如果grp已经是一个因素,它会更干净一些。