Graphics Reference
In-Depth Information
Figure 15-1. Left: original data; middle: reordered by the mean of each group; right: reordered by
the median of each group
In the middle graph in Figure 15-1 , the boxes are sorted by the mean. The horizontal line that
runs across each box represents the medianof the data. Notice that these values do not increase
strictly from left to right. That's because with this particular data set, sorting by the mean gives a
different order than sorting by the median. To make the median lines increase from left to right,
as in the graph on the right in Figure 15-1 , we used the median() function in reorder() .
See Also
Reordering factor levels is also useful for controlling the order of axes and legends. See Recipes
and for more information.
Changing the Names of Factor Levels
Problem
You want to change the names of levels in a factor.
Solution
Use revalue() or mapvalues() from the plyr package:
sizes <- factor(c( "small" , "large" , "large" , "small" , "medium" ))
sizes
small large large small medium
Levels: large medium small
levels(sizes)
 
 
Search WWH ::




Custom Search