Is there anyway to reorder factors in a polycharts heatmap in rCharts?
I have tried reorder it in data frame, but no luck.
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
You can specify the sort order with 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
You could try appending a zero before all single digit entries under dat$day1
. Its not the neatest solution but after trying this out and not succeeding , it would seem that rPlot
prioritizes alphabetical ordering over factor levels. Looking forward to a neater solution from someone :-)
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.