简体   繁体   English

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

[英]R - plotly - cannot sort graph by value

I have some data that is sorted but in plotly the horizontal bar is only sorting in reverse alphabetical order but I need it to sort by a VALUE which is a number; 我有一些已排序的数据,但是在水平图中,水平条仅按相反的字母顺序排序,但是我需要它按数值VALUE进行排序; see image 'YOY' column. 参见图片“同比”列。 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 在此处输入图片说明

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM