Graphics Reference
In-Depth Information
When you use theme() to set axis.title.x=element_blank() , the name of the xor yscale
is unchanged, but the text is not displayed and no space is reserved for it. When you set the label
to "" , the name of the scale is changed and the (empty) text does display.
Changing the Appearance of Axis Labels
Problem
You want to change the appearance of axis labels.
Solution
To change the appearance of the x-axis label ( Figure 8-22 ), use axis.title.x :
library(gcookbook) # For the data set
hwp <- ggplot(heightweight, aes(x=ageYear, y=heightIn)) + geom_point()
hwp + theme(axis.title.x=element_text(face="italic", colour="darkred", size=14))
Discussion
For the y-axis label, it might also be useful to display the text unrotated, as shown in Figure 8-23
(left). The \n in the label represents a newline character:
hwp + ylab("Height\n(inches)") +
theme(axis.title.y=element_text(angle=0, face="italic", size=14))
When you call element_text() , the default angle is 0, so if you set axis.title.y but don't
specify the angle, it will show in this orientation, with the top of the text pointing up. If you
change any other properties of axis.title.y and want it to be displayed in its usual orienta-
tion, rotated 90 degrees, you must manually specify the angle ( Figure 8-23 , right):
hwp + ylab("Height\n(inches)") +
theme(axis.title.y=element_text(angle=90, face="italic", colour="darkred",
size=14))
Search WWH ::




Custom Search