Problem
I wanted to reverse the order of the x axis in a bar chart. I eventually succeeded with this:
tinyplot(
~cyl,
data = mtcars,
type = "barplot",
beside = TRUE
,xlevels = levels(factor(mycars$cyl))[3:1]
)
However, the helptext "a character or numeric vector specifying in which order the levels of the x variable should be plotted. " does not make it clear that that each element of the vector must be a match for one of the levels of x, not an index. I would have initially expected xlevels = 3:1 (indices) and/or xlevels = c(8, 6, 4) (actual x values passed in). These resulted in
Error in (function (datapoints, col, bg, lty, lwd, palette, xlab = NULL, :
object 'x' not found
which does not indicate why my values are invalid or what valid values might be.
Suggested Remedies
- Fix the error message: run a check on the xlevel param to check if it matches levels of x. If not, error with something like "xlevels must match levels of x".
- Clarify the parameter description as to what values are acceptable and what they do.
- Add an example to barplots examples or gallery where xlevel is set.
- Accept numeric input. Either if x is numeric, allow xlevels to be values of x OR accept level indices. (Obviously doing both would create conflicts, but seems like one or the other could be done.)
Hope this is helpful!
Problem
I wanted to reverse the order of the x axis in a bar chart. I eventually succeeded with this:
However, the helptext "a character or numeric vector specifying in which order the levels of the x variable should be plotted. " does not make it clear that that each element of the vector must be a match for one of the levels of x, not an index. I would have initially expected
xlevels = 3:1(indices) and/orxlevels = c(8, 6, 4)(actual x values passed in). These resulted inwhich does not indicate why my values are invalid or what valid values might be.
Suggested Remedies
Hope this is helpful!