order of stacked bars in ggplot

后端 未结 1 1060
时光取名叫无心
时光取名叫无心 2021-01-20 22:16

I am trying to figure out diverging stacked bar charts made in ggplot. I followed an example posted here. Everything works out, except the order of the stacked bars on the

1条回答
  •  醉梦人生
    2021-01-20 22:30

    You need to fix the order of your fill variable (color) by adding these two lines (before ggplot):

      my.lows$color <- factor(my.lows$color, levels = my.colors, ordered = TRUE)
      my.highs$color <- factor(my.highs$color, levels = rev(my.colors), ordered = TRUE)
    

    Then the plot looks like this:

    0 讨论(0)
提交回复
热议问题