Graphics Reference
In-Depth Information
Discussion
There are actually three related items that can be controlled: tick labels, tick marks, and the grid
lines. For continuous axes, ggplot() normally places a tick label, tick mark, and major grid line
at each value of breaks . For categorical axes, these things go at each value of limits .
The tick labels on each axis can be controlled independently. However, the tick marks and grid
lines must be controlled all together.
Changing the Text of Tick Labels
Problem
You want to change the text of tick labels.
Solution
Consider the scatter plot in Figure 8-15 , where height is reported in inches:
library(gcookbook) # For the data set
hwp <- ggplot(heightweight, aes(x = ageYear, y = heightIn)) +
geom_point()
hwp
To set arbitrary labels, as in Figure 8-15 (right), pass values to breaks and labels in the scale.
One of the labels has a newline ( \n ) character, which tells ggplot() to put a line break there:
hwp + scale_y_continuous(breaks = c( 50 , 56 , 60 , 66 , 72 ),
labels = c( "Tiny" , "Really\nshort" , "Short" ,
"Medium" , "Tallish" ))
Search WWH ::




Custom Search