Я хочу изменить порядок столбцов на следующем графике:
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
Порядок должен быть «нет», «мало», «несколько», «много».
Это решение у меня не работает:
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
Спасибо!
effectiveness[with(effectiveness, order(data, Ranking)), ]
- person rawr   schedule 04.08.2015