Order multiple variables in ggplot2

前端 未结 3 982
轮回少年
轮回少年 2021-02-15 23:59

I\'m attempting to group variables within variables and sort in descending order.

mydf

region  airport value
MIA         FLL 0.244587909
MIA         PBI         


        
3条回答
  •  日久生厌
    2021-02-16 00:11

    Neither of these answers worked for me because I was summarizing data before graphing. After WAY too much time I managed to get it to work. I'm adding generic variables because I don't know how to get it to run on someone elses' data. If anyone wants to replace in the data to make the output actually run with this example be my guest.

    Also, you have to round otherwise the mean_se output otherwise you get a massive label.

    df%>% 
      group_by(X1, X2) %>% 
     summarize(group = mean_se(Outcome))%>% 
      ggplot(aes(x = X1 %>% fct_reorder(., group$y), y = round(group$y,2) %>% reorder(.,group$y), fill = X2))+
     geom_col(position = position_dodge(0.9)) +
      geom_errorbar(aes(ymin =round(group$ymin,2)%>% reorder(.,group$y) , ymax = round(group$ymax,2)%>% reorder(.,group$y)), width = 0.25, size = 1, position=position_dodge(0.95))
    

提交回复
热议问题