reorderis a generic function. The
"default"method treats its first argument as a categorical variable, and reorders its levels based on the values of a second variable, usually numeric.
## S3 method for class 'default': reorder(x, X, FUN = mean, \dots, order = is.ordered(x))
xis not a factor, its unique values will be used as the implicit levels.
x, whose subset of values for each unique level of
xdetermines the eventual order of that level.
Xdetermined by the levels of
order), with the order of the levels determined by
x. The levels are ordered such that the values returned by
FUNare in increasing order. Empty levels will be dropped.
Additionally, the values of
FUN applied to the subsets of
X (in the original order of the levels of
x) is returned
require(graphics) bymedian <- with(InsectSprays, reorder(spray, count, median)) boxplot(count ~ bymedian, data = InsectSprays, xlab = "Type of spray", ylab = "Insect count", main = "InsectSprays data", varwidth = TRUE, col = "lightgray")