ggplot with error bars for two measurement variables and one factor

Viewed 3139

I know how to create regular plots with error bars for, say, one factor (e.g. experiment) and one measurement (e.g. quality). I first summarize the data to get mean and CI using the summarySE function given on this site. For example:

   hrc_id experiment  N  quality        sd         se         ci
        0      FB_IS 77 3.584416 0.6757189 0.07700532 0.15336938
        0     FB_ACR 77 3.779221 0.6614055 0.07537416 0.15012064
        1      FB_IS 77 3.038961 0.7854191 0.08950681 0.17826826
        1     FB_ACR 77 3.129870 0.8483831 0.09668223 0.19255935
...

That way I could plot:

ggplot(d, aes(hrc_id, quality), quality, color = experiment)) + 
    geom_point(position = position_dodge(width = .5)) +
    geom_errorbar(aes(ymin = quality - ci, ymax = quality + ci), width = .5, position = "dodge")


However, now I have to do the same with two measurements—not just quality, but also confidence. For example, my data might look as follows:

hrc_id confidence confidence_ci  quality quality_ci
     0   3.573718    0.02068321 4.576923 0.02864818
     1   3.403846    0.03193104 1.658120 0.04441434
    10   3.160256    0.02520483 3.038462 0.04476492
...

How would I go about plotting confidence (with confidence_ci) and quality (with quality_ci) next to each other, for each hrc_id?

I thought I could melt the dataframe so that confidence and quality would be the measurement variables, but then I lose the CI values that belong to them.

2 Answers
Related