R: Levels/Labels for ordinal variables and the boxplot function -


i used have ordinal data plain numbers in data frame (i.e. 1-3). worked out fine, had remember numbers stood (in case: 1=low, 2=medium, 3=high).

to make things easier me trying r display names/labels instead of 1-3 in generic fashion, i.e. regardless of whether using tables, boxplots, etc. however, can't work.

i tried

data$var <- ordered(data$var,      levels = c(1, 2, 3),      labels = c("low", "medium", "high"))  

after this, a

boxplot(data$var) 

does not work anymore. why not?

the command didn't work because boxplot expecting first argument (the x argument), numeric.

if you're looking simple solution, plot data integers (as factors ordered, therefore in right integer order) suppress original axes , add new 1 right axis labels.

boxplot(as.integer(data$var), yaxt = "n") axis(2, @ = c(1, 2, 3), labels = c("low", "medium", "high")) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -