Graphics Reference
In-Depth Information
Solution
For the x-axis label, use theme(axis.title.x=element_blank()) . For the y-axis label, do
the same with axis.title.y .
We'll hide the x-axis in this example ( Figure 8-21 ):
p <- ggplot(PlantGrowth, aes(x = group, y = weight)) + geom_boxplot()
p + theme(axis.title.x = element_blank())
Figure 8-21. Left: x-axis label with element_blank(); right: with the label set to ""
Discussion
Sometimes axis labels are redundant or obvious from the context, and don't need to be displayed.
In the example here, the x-axis represents group , but this should be obvious from the context.
Similarly, if the ytick labels had kgor some other unit in each label, the axis label “weight”
would be unnecessary.
Another way to remove the axis label is to set it to an empty string. However, if you do it this
way, the resulting graph will still have space reserved for the text, as shown in the graph on the
right in Figure 8-21 :
p + xlab( "" )
Search WWH ::




Custom Search