是否有重新排序rCharts中polycharts热图中的因子?
我尝试在数据框中重新排序,但没有运气。
library(rCharts)
dat <- data.frame(day1=rep(c("day 1", "day 2" ,"day 10"),3),
day2=rep(c("Mon","Sun","wed"),3),
value=1:9)
dat$day1 <- factor(dat$day1, levels = c('day 1', 'day 2', 'day 10'))
plot <- rPlot(day1 ~ day2, color = 'value', data = dat ,type = 'tile', height = 600)
plot
答案 0 :(得分:3)
您可以使用guides
指定排序顺序:
library(rCharts)
dat <- data.frame(day1=rep(c("day 1", "day 2" ,"day 10"),3),
day2=rep(c("Mon","Sun","wed"),3),
value=1:9)
plot <- rPlot(day1~day2, color = 'value', data = dat, type = 'tile')
# reverse the levels if you want the axis ordered in reverse
plot$guides(x = list(levels = c('Sun', 'Mon', 'wed')),
y = list(levels = c('day 1', 'day 2', 'day 10')))
# i think you need to specify width & height this way
plot$addParams(width = 400, height = 400)
plot
答案 1 :(得分:1)
您可以尝试在dat$day1
下的所有单个数字条目之前添加零。它不是最新的解决方案,而是after trying this out and not succeeding,似乎rPlot
优先考虑因子级别的字母排序。期待有人提供更简洁的解决方案: - )
dat<-data.frame(day1=rep(c("day 01", "day 02" ,"day 10"),3),
day2=rep(c("Mon","Sun","wed"),3), value=1:9)`
dat$day1 <- factor(dat$day1, levels = c('day 01', 'day 02', 'day 10'), ordered=T)
plot <- rPlot(day1 ~ day2, color = 'value', data = dat ,type ='tile', height=600)
plot