2016-11-08 43 views
1

我一直在努力重新安排我的地塊之一的傳說。下面的例子ilustrates我目前遇到的問題:重新安排傳奇在情節盒圖

library(plotly) 
library(data.table) 

test <- data.table(NAME = c(rep(x = "b",10),rep(x = "c",10),rep(x = "a",10)), VALUE = sample(0:100,30, replace = T)/100) 

plot_ly(test, x = ~NAME, y = ~VALUE, color = ~NAME, type = "box") 

所以,當我運行函數什麼,我得到的是與按字母順序排列的傳奇人物(「A」,「B」,「C」)的陰謀並且根據圖例排列(從左到右)箱形圖。我試圖得到的是一個圖例,其圖例遵循與數據集中相同的順序(「b」,「c」,「a」)和相應的盒形圖。

回答

2

我不知道該怎麼做,與Plotly,而是一個解決方法是通過在data.frame因素,並將它們順序數據集中,以替換字符:

test$NAME <- factor(test$NAME, levels=unique(test$NAME)) 
plot_ly(test, x = ~NAME, y = ~VALUE, color = ~NAME, type = "box") 

enter image description here