How to do I reorder the factor in my dPlot
, as such that "Exceptional" is located at the most left, followed by "Fine", "Mediocre", "Trouble", "Danger", and "Critical".
Dataset:
dat<-structure(list(MainDept = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L,
5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), .Label = c("Business Development",
"Finance Department", "HR & Admin Department", "Manufacturing & Engineering Department",
"QA Department", "Supply Chain Department"), class = "factor"),
Level = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c("Critical",
"Danger", "Exceptional", "Fine", "Mediocre", "Trouble"), class = "factor"),
Freq = c(0L, 0L, 0L, 29L, 0L, 0L, 0L, 0L, 0L, 108L, 0L, 0L,
0L, 0L, 2L, 7L, 12L, 15L, 0L, 7L, 15L, 16L, 73L, 59L, 12L,
0L, 0L, 191L, 0L, 0L, 11L, 0L, 0L, 128L, 0L, 0L)), .Names = c("MainDept",
"Level", "Freq"), row.names = c(NA, -36L), class = "data.frame")
The code to generate the plot:
require(rCharts)
plot<-dPlot(y="MainDept", x="Freq",data=dat,groups="Level",type="bar",width=1200)
plot$yAxis(type="addCategoryAxis")
plot$xAxis(type="addPctAxis")
plot$legend(
x = 0,
y = 0,
horizontalAlign = "right"
)
I tried with:
dat$Level<-as.character(dat$Level)
dat$Level[dat$Level=="Exceptional"]<-1
dat$Level[dat$Level=="Fine"]<-2
dat$Level[dat$Level=="Mediocre"]<-3
dat$Level[dat$Level=="Trouble"]<-4
dat$Level[dat$Level=="Danger"]<-5
dat$Level[dat$Level=="Critical"]<-6
dat$Level<-as.factor(dat$Level)
Thank you.