Graphics Reference
In-Depth Information
Figure 8-19. Left: scatter plot with the default axis labels; right: manually specified labels for the
x- and y-axes
Discussion
By default the graphs will just use the column names from the data frame as axis labels. This
might be fine for exploring data, but for presenting it, you may want more descriptive axis labels.
Instead of xlab() and ylab() , you can use labs() :
hwp + labs(x = "Age in years" , y = "Height in inches" )
Another way of setting the axis labels is in the scale specification, like this:
hwp + scale_x_continuous(name = "Age in years" )
This may look a bit awkward, but it can be useful if you're also setting other properties of the
scale, such as the tick mark placement, range, and so on.
This also applies, of course, to other axis scales, such as scale_y_continuous() ,
scale_x_discrete() , and so on.
You can also add line breaks with \n , as shown in Figure 8-20 :
hwp + scale_x_continuous(name = "Age\n(years)" )
Search WWH ::




Custom Search