简体   繁体   中英

Overlapping confidence interval with ggplot

I'd like to plot two confidence intervals with geom_ribbon in PSO and PSOA . My dataset is given by

id   Meta prob       mean    lowerci   upperci
1   PSO  0.1 6705423.00   9913.939  151671.3
2   PSO  0.2 6705423.00  24352.031  393418.7
3   PSO  0.3 6705423.00  64719.335  444035.0
4   PSO  0.4 6705423.00  85058.168  600026.5
5   PSO  0.5 6705423.00 140437.916  756819.1
6   PSO  0.6 6705423.00 179236.196  952494.7
7   PSO  0.7 6705423.00 211278.350  773605.9
8   PSO  0.8 6705423.00 169915.851 1078624.1
9   PSO  0.9 6705423.00 263216.389  936007.2
10  PSO  1.0 6705423.00 266200.032 1061063.0
11 PSOA  0.1   52460.43   9913.939  151671.3
12 PSOA  0.2  202813.18  24352.031  393418.7
13 PSOA  0.3  252836.56  64719.335  444035.0
14 PSOA  0.4  329661.97  85058.168  600026.5
15 PSOA  0.5  450833.52 140437.916  756819.1
16 PSOA  0.6  424932.84 179236.196  952494.7
17 PSOA  0.7  486794.40 211278.350  773605.9
18 PSOA  0.8  634493.58 169915.851 1078624.1
19 PSOA  0.9  521509.18 263216.389  936007.2
20 PSOA  1.0  648183.78 266200.032 1061063.0

I tried to use the code above, but I could not plot the geom_ribbon in PSO ("HERE" in figure).

p <- ggplot(data=dat2, aes(x=prob, y=mean, colour=Meta)) + geom_point() + geom_line()
p <- p + geom_ribbon(aes(ymin=dat2$lowerci, ymax=dat2$upperci), linetype=2, alpha=0.1)

在此处输入图片说明

The issue is that the data for lowerci and upperci is exactly the same for the PSO and PSOA groups. When plotted, the PSOA group is "covering up" the PSO group giving the appearance it is not being plotted. To see how this is working you can run the same code with just a subset of your data:

ggplot(data=dat2[dat2$Meta == "PSO",], aes(x=prob, y=mean, colour=Meta)) + geom_point() + geom_line() +
        geom_ribbon(aes(ymin=lowerci, ymax=upperci), linetype=2, alpha=0.1)

Note how the ribbon for PSO looks identical to your original plot?

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM