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

10. Legends > Changing the Appearance of Legend Labels

Changing the Appearance of Legend Labels

Problem

You want to change the appearance of labels in a legend.

Solution

Use theme(legend.text=element_text()) (Figure 10-16):

# The base plot
p <- ggplot(PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()

# Change the legend label appearance
p + theme(legend.text=element_text(face="italic", family="Times", colour="red", 
                                   size=14))
Customized legend label appearance
Figure 10-16. Customized legend label appearance

Discussion

It’s also possible to specify the legend label appearance via guides(), although this method is a bit unwieldy. This has the same effect as the previous code:

# Changes the legend title text for the fill legend
p + guides(fill=guide_legend(label.theme=
           element_text(face="italic", family="Times", colour="red", size=14)))

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free 10-Day Trial


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