Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. Axes > Removing Axis Labels

Removing Axis Labels

Problem

You want to remove the label on an axis.

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())
Left: with element_blank(); right: with the label
            set to ""
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 y tick labels had kg or some other unit in each label, the axis label “weight” would be unnecessary.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint