R-绘图-无法按值对图形排序

时间:2019-07-01 11:12:45

标签: r plotly

我有一些已排序的数据,但是在水平图中,水平条仅按字母相反的顺序排序,但是我需要按数值VALUE对其进行排序;参见图片“同比”列。 enter image description here

ecomm_yoy <- ecomm_data2019 %>%
      inner_join(ecomm_data2018, by = "Brand") %>%
      mutate(YOY = round(((Value.x - Value.y)/Value.y)*100, 2)) 

    ecomm_yoy2 <- ecomm_yoy[order(-ecomm_yoy$YOY),]

    plot_ly(x = ecomm_yoy2$YOY, y = ecomm_yoy2$Brand, type = 'bar', orientation = 'h') 

enter image description here

1 个答案:

答案 0 :(得分:0)

将此布局(使用管道)添加到图表中

layout(yaxis = list(categoryorder = "array", categoryarray = ecomm_yoy2$YOY))