我在hplot(rCharts)中的xAxis顺序以及将鼠标悬停在绘图上时有问题。我有一个按月和付款状态排序的数据框,我想在我的xAxis中使用月,但是,我看到,当鼠标悬停在系列上时,例如显示Apr而不是Jan。我了解hPlot按字母顺序排序,但是,我想“同步”这两个信息。
有没有办法做到这一点?
library(rCharts)
monthUnique <- data.frame(month=c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))
monthUnique <- monthUnique[rep(seq_len(nrow(monthUnique)), each=4),]
monthStatus <- data.frame(month = monthUnique, status = rep(c("Canceled","Pending","Paid","Suspended"),12),students = sample(1:50,48))
graph <- hPlot(students~month, data = monthStatus, type = c('column'), group = 'status', title = "Status by month")
graph$yAxis(title = list(text = ""),labels = list(style = list(fontSize = "15px")))
graph$legend(align = 'right', verticalAlign = 'top', layout = 'vertical')
ord <- c("Canceled"=0,"Pending"=1,"Paid"=2,"Suspended"=3)
graph$params$series <- lapply(graph$params$series, function(d){
temp = ord[d$name]
names(temp) = NULL
d$legendIndex = temp
return(d)
})
graph$colors('rgba(255, 0, 0, 0.45)', 'rgba(249, 120, 0, 0.45)', 'rgba(174,62,208, 0.45)', 'rgba(177,177,177, 0.45)')
graph$xAxis(categories = unique(mesfinal$mes), title = list(text = ""),labels = list(style = list(fontSize = "15px")))
graph