Graphics Reference
In-Depth Information
Mole
0.122
3.0
Pig
192.000 180.0
As shown in Figure 8-26 , we can make a scatter plot to visualize the relationship between brain
and body mass. With the default linearly scaled axes, it's hard to make much sense of this graph.
Because of a few very large animals, the rest of the animals get squished into the lower-left
corner—a mouse barely looks different from a triceratops! This is a case where the data is dis-
tributed exponentially on both axes.
Ggplot2 will try to make good decisions about where to place the tick marks, but if you don't
like them, you can change them by specifying breaks and, optionally, labels . In the example
here, the automatically generated tick marks are spaced farther apart than is ideal. For the y-axis
tick marks, we can get a vector of every power of 10 from 10 0 to 10 3 like this:
10 ^ ( 0 : 3 )
1
10 100 1000
The x-axis tick marks work the same way, but because the range is large, R decides to format
the output with scientific notation:
10 ^ ( -1 : 5 )
1 e - 01 1 e + 00 1 e + 01 1 e + 02 1 e + 03 1 e + 04 1 e + 05
And then we can use those values as the breaks, as in Figure 8-27 (left):
p + scale_x_log10(breaks = 10 ^ ( -1 : 5 )) + scale_y_log10(breaks = 10 ^ ( 0 : 3 ))
Search WWH ::




Custom Search