1

I have some data of counts of households broken up into different salary buckets and neighborhoods. I also have their margin of errors. I want to display the symbol (or line) of the margin of error in the legend but can't seem to find a solution.

This is my data:

id  Hood    Bracket         Estimate    Margin   Max.MOE    Min.MOE
1   A       Less than 20k   291         77.38    368.38     213.62
2   B       Less than 20k   123         44.18    167.18     78.82
3   C       Less than 20k   493         107.23   600.23     385.77
4   D       Less than 20k   332         98.94    430.94     233.06
5   E       Less than 20k   631         144.16   775.16     486.84
6   A       20k to 35k      220         63.86    283.86     156.14
7   B       20k to 35k      226         70.82    296.82     155.18
8   C       20k to 35k      25          16.82    41.82      8.18
9   D       20k to 35k      253         91.4     344.4      161.6
10  E       20k to 35k      578         126.38   704.38     451.62

This is my r code:

ggplot (data = df1,
        aes (x = Hood,
             y = Estimate,
             fill = Bracket )) +

    geom_col(position = position_dodge(width = 0.9)) +
    geom_errorbar(aes(ymin = Min.MOE,
                      ymax = Max.MOE),
                  position = position_dodge(width = 0.9), 
                  width = 0.2) 

I would prefer the error bars to remain black and in the legend say something like, "Margin of Error" along with the different brackets.

divibisan
  • 11,659
  • 11
  • 40
  • 58
  • 1
    If you want to force a legend for an aesthetic that isn't actually changing, you can use a dummy variable inside your `aes` for the errorbars – camille Aug 08 '18 at 20:28
  • 2
    Something like this https://stackoverflow.com/a/49644500/786542? – Tung Aug 08 '18 at 21:27

0 Answers0