geom_errorbar not dodging or producing horizontal line
0
0
Entering edit mode
22 months ago
bsp017 ▴ 50

enter image description hereI would like my plot to have horizontal lines at the top and bottom of error bars. Is there a way to make sure they appear? Also the position dodge does not seem to work. The vertical error bar lines are not dodging.

library(dplyr)
library(stringr)
library(ggplot2)

ggplot(data2, aes(x=Cohort, y=Mean_R2, color = Trait)) +
  geom_errorbar(aes(ymin=Mean_R2+SD, ymax=Mean_R2-SD), position=position_dodge(0.05))+
    xlim(0, 10000)

Data

    Trait   Cohort  Mean_R2 SD  Trait_color
    Color   10  0.02947673  0.02082434  Color
    Color   50  0.2259004   0.04675703  Color
    Color   100 0.3245573   0.04779442  Color
    Color   500 0.4892648   0.04745342  Color
    Color   1000    0.5447884   0.04178 Color
    Color   5000    0.5954482   0.0355258   Color
    Color   10000   0.632652    0.03706049  Color
    Color   25000   0.6181629   0.03825963  Color
    Color   50000   0.6079681   0.04134136  Color
    Color   100000  0.5880006   0.0465956   Color
    Color   1000000 0.4801181   0.05596124  Color
    Health  10  0.1669139   0.03696639  Health
    Health  50  0.448158    0.04392942  Health
    Health  100 0.4819306   0.04525248  Health
    Health  500 0.4788394   0.05993038  Health
    Health  1000    0.5137877   0.05924604  Health
    Health  5000    0.5665759   0.05810662  Health
    Health  10000   0.5921626   0.05924604  Health
    Health  25000   0.6366738   0.06368359  Health
    Health  50000   0.6277492   0.0692886   Health
    Health  100000  0.6023589   0.07283448  Health
    Health  1000000 0.4107126   0.1088985   Health
ggplot2 geom_errorbar • 1.4k views
ADD COMMENT
0
Entering edit mode
ggplot(data2, aes(x=Cohort, y=Mean_R2, color = Trait)) +
geom_errorbar(aes(ymin=Mean_R2+SD, ymax=Mean_R2-SD), position="dodge")+
geom_hline(yintercept = Mean_R2+SD, color = 'cadetblue')+
xlim(0, 10000)

let me know if this works.

ADD REPLY
0
Entering edit mode

I get the following error:

ggplot(data2, aes(x=Cohort, y=Mean_R2, color = Trait)) +
+   geom_errorbar(aes(ymin=Mean_R2+SD, ymax=Mean_R2-SD), position="dodge")+
+   geom_hline(yintercept = Mean_R2+SD, color = 'cadetblue')+
+   xlim(0, 10000)
Error in list2(...) : object 'Mean_R2' not found
ADD REPLY
0
Entering edit mode
ggplot(data2, aes(x=Cohort, y=Mean_R2, color = Trait)) +
geom_errorbar(aes(ymin=Mean_R2+SD, ymax=Mean_R2-SD), position="dodge")+
geom_hline(yintercept = data2$Mean_R2+SD)+
xlim(0, 10000)

Sorry should be this. Assuming SD is already assigned a value.

ADD REPLY
0
Entering edit mode

SD is already assigned. The image is not correct.

enter image description here

ADD REPLY

Login before adding your answer.

Traffic: 2394 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6