Paschalis
Paschalis

Reputation: 12301

Place geom_text below confidence intervals of a bar plot

How can I place geom_text below the confidence intervals(geom_errorbar) of a bar plot?

The solutions I 've tried (but I did not liked):

1. Change the colour and place it at the top of a bar char. This is good, but white on some colours is just wrong:

White on yellow?!

2. Put a high vjust, so it can go below the confidence intervals. Again, this is good, but not good enough. Not all intervals have the same height:

Different interval sizes

Upvotes: 1

Views: 586

Answers (1)

Paschalis
Paschalis

Reputation: 12301

I eventually found a way to dynamically place the geom_text approximately below the confidence intervals. You might need to adjust the numbers: 1.5, and 25.

Basically it sums a number that is proportionate to the confidence intervals, and a constant value, that is that is approximately the same with the text's height.

   geom_text(data=statSummary, aes(label=sprintf("%.02f",time)),
        vjust=1.5 +
          ((statSummary$time -
          (statSummary$time-statSummary$ci))
        /
        (statSummary$time))*25
        ,
        position=position_dodge(width=0.9),
        show_guide=F,
        color="black")

If you use a ruler you might find the result not perfect, but it is much better: enter image description here

Upvotes: 1

Related Questions