Graphics Reference
In-Depth Information
In ggplot2, there are two ways of setting the range of the axes. The first way is to modify the
scale, and the second is to apply a coordinatetransform. When you modify the limits of the xor
yscale, any data outside of the limits is removed—that is, the out-of-range data is not only not
displayed, it is removed from consideration entirely.
With the box plots in these examples, if you restrict the yrange so that some of the original data
is clipped, the box plot statistics will be computed based on clipped data, and the shape of the
box plots will change.
With a coordinate transform, the data is not clipped; in essence, it zooms in or out to the specified
range. Figure 8-4 shows the difference between the two methods:
p + scale_y_continuous(limits = c( 5 , 6.5 )) # Same as using ylim()
p + coord_cartesian(ylim = c( 5 , 6.5 ))
Figure 8-4. Left: smaller y range using a scale (data has been dropped, so the box plots have
changed shape); right: “zooming in” using a coordinate transform
Finally, it's also possible to expandthe range in one direction, using expand_limits() ( Fig-
ure 8-5 ) . You can't use this to shrink the range, however:
p + expand_limits(y = 0 )
Search WWH ::




Custom Search