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 a Legend Title

Changing the Appearance of a Legend Title

Problem

You want to change the appearance of a legend title’s text.

Solution

Use theme(legend.title=element_text()) (Figure 10-11):

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

p + theme(legend.title=element_text(face="italic", family="Times", colour="red", 
                                    size=14))
Customized legend title appearance
Figure 10-11. Customized legend title appearance

Discussion

It’s also possible to specify the legend title’s appearance via guides(), but this method can be a bit verbose. This has the same effect as the previous code:

p + guides(fill=guide_legend(title.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