1
votes

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)

enter image description here

1
You can't plot the ribbon there because the y-values of the ribbon are identical to the PSOA group. Thus, it looks like you aren't plotting the PSO group but it is being plotted. It just is being covered by the PSOA groupMike H.
Do you actually want to plot something like ymax = mean + upperci and ymin = mean - lowerci?Mike H.
The mean of PSO is equal, but the limits of confidence intervals are different. In addition, I'd like ymax = upperci, ymax = mean + upperci is very greater ymax = upperci.Wagner Jorge
Yes the limits differ within the PSO group. However, the upperci and lowerci are identical across the PSO and PSOA group causing PSO to be covered upMike H.
Ok, but your CIs dont really make sense for the PSO group because the mean is not even close to contained within themMike H.

1 Answers

2
votes

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?

enter image description here