有没有办法使用串扰对象根据另一列的值对绘图条进行排序或排序,就像我们使用因子水平对普通数据框所做的一样?我的数据看起来像这样;
df<-data.frame(Country=c("Afghanistan","Albania", "Algeria", "Andorra" , "Angola" , "Antigua and Barbuda", "Argentina" , "Armenia",
"Azerbaijan","Bahamas"), Total=c(18.80, 19.00 , 0.60 , 0.00 , 1.72 , 44.20 ,185.00 ,122.30 , 4.90 , 6.70 ),Projects=c(17.2, 15.4, 0.3 , NA, 1.3, 39.4, 185.0, 118.1, 3.8, 4.0))
# created shared object and used it in plot_ly
library(crosstalk)
shared_df<-SharedData$new(df)
bscols(
plot_ly(shared_df, type='bar', x=~Country, y=~Total, showlegend=F)
#but factoring or ordering doesn't work on this
因此,理想情况下,我想根据 Total 或 Projects 值对国家进行排序。最终产品应该是这样的; 订购吧 谢谢!