r – How to center ggplot label on multiple geom_pointranges (three or more)?

I created a point range chart in ggplot2 but the labels are not directly centered over the points (see the figure and the code below).

How do I center each label over its respective point in this plot? I have asked this question before but the solution only works for two point ranges, not three.

Here is the data:

DF <-  structure(list(Label = c("(Intercept)", "constituency.cfscore", 
                           "(Intercept)", "constituency.cfscore", "In_Distict_contributor.cfscore_mean", 
                           "(Intercept)", "constituency.cfscore", "contributor.cfscore_mean", 
                           "In_Distict_contributor.cfscore_mean", "(Intercept)", "constituency.cfscore", 
                           "(Intercept)", "constituency.cfscore", "In_Distict_contributor.cfscore_mean", 
                           "(Intercept)", "constituency.cfscore", "contributor.cfscore_mean", 
                           "In_Distict_contributor.cfscore_mean", "(Intercept)", "constituency.cfscore", 
                           "(Intercept)", "constituency.cfscore", "In_Distict_contributor.cfscore_mean", 
                           "(Intercept)", "constituency.cfscore", "contributor.cfscore_mean", 
                           "In_Distict_contributor.cfscore_mean"), Coeff = c(0.127768856542629, 
                                                                             1.56864212817933, 0.101925619104429, -0.159643211445582, 0.964395059882224, 
                                                                             0.108011652893671, -0.140569400522949, 0.605239723713925, 0.556488910417634, 
                                                                             0.166257398377357, 1.96475524613597, 0.130891353414459, -0.0389343513848743, 
                                                                             0.911675205841863, 0.135990099028917, -0.0822913145608767, 0.238296092267945, 
                                                                             0.769617381086265, 0.129564854856298, 2.08492474220601, 0.10553394041394, 
                                                                             0.0873681655038371, 0.847702270479957, 0.113335883974078, 0.071993324347194, 
                                                                             0.671973453659251, 0.412668819904254), SE = c(0.0522799284176104, 
                                                                                                                           0.224300766313731, 0.0131946186826885, 0.0724707902051118, 0.0240175722255338, 
                                                                                                                           0.0112661883622242, 0.0617393504199305, 0.0916007473092931, 0.0650304304807207, 
                                                                                                                           0.0449524420600281, 0.194806165206098, 0.00891634534598981, 0.0540583095228576, 
                                                                                                                           0.0170563220708003, 0.00868220295158976, 0.0534337346640461, 
                                                                                                                           0.0719798927251469, 0.0459177070639869, 0.0407985735361107, 0.189757956376198, 
                                                                                                                           0.015257058056211, 0.104359801218137, 0.0324499241803258, 0.0126976605551819, 
                                                                                                                           0.0865630258034629, 0.0932882572759313, 0.0661175933790659), 
                 t.value = c(2.44393709803914, 6.99347645556084, 7.72478701776781, 
                             -2.20286284989785, 40.1537278966501, 9.58724010472224, -2.27682020570095, 
                             6.60736665903295, 8.55736162753242, 3.69851760568074, 10.0856933560461, 
                             14.6799331267858, -0.720228799763181, 53.4508671950217, 15.6630868671432, 
                             -1.54006294110391, 3.31059248973699, 16.7607973110198, 3.17572021829686, 
                             10.9872849709269, 6.91705701224478, 0.837182176317268, 26.1233975700293, 
                             8.92572954533943, 0.831686781728856, 7.20319441354408, 6.24143739682627
                 ), P.Value = c(0.0160468226405564, 1.88551050046972e-10, 
                                5.15151105928388e-12, 0.0296523116429465, 2.49036624613981e-68, 
                                3.20042594300278e-16, 0.0247139495319937, 1.40942276524859e-09, 
                                7.26312343056369e-14, 0.000334035139625155, 1.60910673065283e-17, 
                                7.40677294741355e-28, 0.472884570542143, 1.49499562195177e-81, 
                                6.99989277427733e-30, 0.126390996120938, 0.00125640596342424, 
                                3.48179466168124e-32, 0.00192282835508655, 1.36655866836994e-19, 
                                3.01121540972409e-10, 0.404273011417672, 1.82714394036555e-49, 
                                1.05322063233179e-14, 0.407371374132731, 7.49412676677533e-11, 
                                8.13126298003365e-09), lower = c(0.0242123800846537, 1.12434547878971, 
                                                                 0.0757821735385093, -0.303234792559804, 0.916807319212795, 
                                                                 0.0856869485561432, -0.262910044918482, 0.423726727922612, 
                                                                 0.427626771178768, 0.077215262153817, 1.57888172504219, 0.113224758054211, 
                                                                 -0.146043962233324, 0.877880290025326, 0.11878573428187, 
                                                                 -0.188173826877511, 0.0956631296659767, 0.678628379207166, 
                                                                 0.0487431949128612, 1.70901569214512, 0.0753040356034319, 
                                                                 -0.119407403235873, 0.783406905314186, 0.0881746219253084, 
                                                                 -0.0995370899767649, 0.487116544215815, 0.281652394806502
                                ), upper = c(0.231325333000604, 2.01293877756895, 0.128069064670348, 
                                             -0.0160516303313593, 1.01198280055165, 0.130336357231198, 
                                             -0.0182287561274168, 0.786752719505239, 0.685351049656501, 
                                             0.255299534600897, 2.35062876722974, 0.148557948774706, 0.0681752594635752, 
                                             0.945470121658399, 0.153194463775965, 0.0235911977557578, 
                                             0.380929054869914, 0.860606382965365, 0.210386514799735, 
                                             2.4608337922669, 0.135763845224448, 0.294143734243547, 0.911997635645727, 
                                             0.138497146022848, 0.243523738671153, 0.856830363102687, 
                                             0.543685245002007), Sig.05 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 
                                                                            1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1), Sig.10 = c(1, 
                                                                                                                                              1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 
                                                                                                                                              1, 0, 1, 1, 0, 1, 1), AdJ.R2 = c(0.292288994750593, 0.292288994750593, 
                                                                                                                                                                               0.955894328664846, 0.955894328664846, 0.955894328664846, 
                                                                                                                                                                               0.968059474878654, 0.968059474878654, 0.968059474878654, 
                                                                                                                                                                               0.968059474878654, 0.464750128761006, 0.464750128761006, 
                                                                                                                                                                               0.979606925637178, 0.979606925637178, 0.979606925637178, 
                                                                                                                                                                               0.981272352371505, 0.981272352371505, 0.981272352371505, 
                                                                                                                                                                               0.981272352371505, 0.510055432779317, 0.510055432779317, 
                                                                                                                                                                               0.932122238210444, 0.932122238210444, 0.932122238210444, 
                                                                                                                                                                               0.953327426145046, 0.953327426145046, 0.953327426145046, 
                                                                                                                                                                               0.953327426145046), DV = c("recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn", "recipient.cfscore.dyn", "recipient.cfscore.dyn", 
                                                                                                                                                                                                          "recipient.cfscore.dyn"), Discontinuity_New_Cut = structure(c(3L, 
                                                                                                                                                                                                                                               3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
                                                                                                                                                                                                                                                                        1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Low", 
                                                                                                                                                                                                                                                                                                                                "Medium", "High"), class = "factor"), Model = structure(c(3L, 
                                                                                                                                                                                                                                                                                                                                                                                          3L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 
                                                                                                                                                                                                                                                                                                                                                                                          1L, 1L, 3L, 3L, 2L, 2L, 2L, 1L, 1L, 1L, 1L), .Label = c("In and Out", 
                                                                                                                                                                                                                                                                                                                                                                                                                                                  "In", "Constituency"), class = "factor")), row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           -27L), class = "data.frame")

Here is the plot code:

ggplot(subset(Result_Master.1, Label != "(Intercept)"), aes(x = Model , y = Coeff, color = Label, shape = Label, ymin = lower, ymax = upper, label = round(Coeff,2))) +
  facet_wrap(Discontinuity_New_Cut  ~ .) +
  geom_text(position = position_dodge(width = 0.65),show.legend = FALSE) +
  geom_pointrange(position = position_dodge(width= 0.4)) +
  coord_flip() +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey") +
  scale_color_manual("Stimuli", labels = c("District Median", "Out-of-District Donor", "In-District Donor"), values = gg_color_hue(3)) +
  scale_shape_manual("Stimuli", labels = c("District Median", "Out-of-District Donor", "In-District Donor"), values = c(16, 17, 18)) +
  theme_bw() 

Thank you!

Leave a Comment