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

12. Using Colors in Plots > Using a Different Palette for a Discrete Variable

Using a Different Palette for a Discrete Variable

Problem

You want to use different colors for a discrete mapped variable.

Solution

Use one of the scales listed in Table 12-1.

Table 12-1. Discrete fill and color scales
Fill scaleColor scaleDescription

scale_fill_discrete()

scale_colour_discrete()

Colors evenly spaced around the color wheel (same as hue)

scale_fill_hue()

scale_colour_hue()

Colors evenly spaced around the color wheel (same as discrete)

scale_fill_grey()

scale_colour_grey()

Greyscale palette

scale_fill_brewer()

scale_colour_brewer()

ColorBrewer palettes

scale_fill_manual()

scale_colour_manual()

Manually specified colors

In the example here we’ll use the default palette (hue), and a ColorBrewer palette (Figure 12-4):


  

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