クロストーク オブジェクトを使用して、別の列の値に従ってプロット バーを並べ替えたり並べ替えたりする方法はありますか?これは、因子レベルを使用する通常のデータ フレームの場合と同じ方法です。私のデータは次のようになります。
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 の値に従って国を並べ替えたいと思います。最終製品は次のようになります。 注文したバー ありがとう!