使用NVD3 rCharts设置MultiBarChart中的因子顺序

时间:2015-08-04 19:13:53

标签: r rcharts

我想更改下图中条形的顺序:

library(rCharts)
effectiveness <- structure(list(Ranking = structure(c(5L, 4L, 3L, 2L, 1L, 5L, 
4L, 3L, 2L, 1L, 5L, 4L, 3L, 2L, 1L, 1L, 2L, 3L, 4L, 5L), .Label = c("Bottom", 
"Bellow Average", "Average", "Above Average", "Top"), class = c("ordered", 
"factor")), Probability = c(0.4, 0.4, 0.1, 0.08, 0.02, 0.1, 0.2, 
0.5, 0.1, 0.1, 0.2, 0.2, 0.2, 0.2, 0.2, 0.01, 0.04, 0.15, 0.7, 
0.1), data = structure(c(4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 
2L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L), .Label = c("none", 
"little", "some", "lots"), class = c("ordered", "factor"))), row.names = c(NA, 
-20L), .Names = c("Ranking", "Probability", "data"), class = "data.frame")

library(rCharts)
n1 <- nPlot(Probability ~ data, group = 'Ranking', data = effectiveness[order(effectiveness$Ranking),], type = 'multiBarChart')
n1$chart(stacked = TRUE)
n1$yAxis( tickFormat = "#!d3.format('%')!#" )
n1$set(width = 1000)
n1$xAxis(axisLabel = "Data available")
n1

订单应该是'不''小''有些''很多'。

This solution对我不起作用:

effectiveness$data <- as.numeric(effectiveness$data)
n1 <- nPlot(Probability ~ data, group = 'Ranking', data = effectiveness[order(effectiveness$Ranking),], type = 'multiBarChart')
n1$chart(stacked = TRUE)
n1$yAxis( tickFormat = "#!d3.format('%')!#" )
n1$set(width = 1000)
n1$xAxis(axisLabel = "Data available")
n1

订单仍为4 2 1 3

谢谢!

0 个答案:

没有答案