Changing plotting order for stacked bar chart

后端 未结 1 1113
面向向阳花
面向向阳花 2021-01-20 11:19

I am trying to change the plotting order of groups in a stacked bar chart. Others have asked similar questions e.g. here and here but I can\'t seem to get anything similar t

相关标签:
1条回答
  • 2021-01-20 12:07

    You can achieve this by ordering the whole data.frame:

    plot1 <- 
      ggplot(data = df[order(df$site, df$group),], 
             aes(x=reorder(site, latitude), y=taxa, fill=group))+
      geom_bar(stat="identity") + 
      coord_flip()
    plot1
    

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