scale_brewer: Sequential, diverging and qualitative colour scales from...

Description Usage Arguments Details Examples

Description

Create colour scales based on ColorBrewer colours.

Usage

1
2
3
4
5
6
7
8
9
scale_colour_brewer(..., type = "seq", palette = 1)

scale_fill_brewer(..., type = "seq", palette = 1)

scale_colour_distiller(..., type = "seq", palette = 1, values = NULL,
  space = "Lab", na.value = "grey50")

scale_fill_distiller(..., type = "seq", palette = 1, values = NULL,
  space = "Lab", na.value = "grey50")

Arguments

...

Other arguments passed on to discrete_scale to control name, limits, breaks, labels and so forth.

type

One of seq (sequential), div (diverging) or qual (qualitative)

palette

If a string, will use that named palette. If a number, will index into the list of palettes of appropriate type

space

colour space in which to calculate gradient. "Lab" usually best unless gradient goes through white.

na.value

Colour to use for missing values

Details

Note: this is an offshoot from ggplot2 with some added functions. I am not sure who the author is as the forum on which this appeared is now down. The functions of interest here are the bottom two, scale_colour_distiller and scale_fill_distiller which allow for nice brewer plots on continuous scales

ColorBrewer provides sequential, diverging and qualitative colour schemes which are particularly suited and tested to display discrete values (levels of a factor) on a map. ggplot2 can use those colours in discrete scales. It also allows to smoothly interpolate the colours to a continuous scale, although the original colour schemes (particularly the qualitative ones) were not intended for this. The perceptual result is left to the appreciation of the user.

See http://colorbrewer2.org for more information.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
(d <- qplot(carat, price, data=dsamp, colour=clarity))

# Change scale label
d + scale_colour_brewer()
d + scale_colour_brewer("clarity")
d + scale_colour_brewer(expression(clarity[beta]))

# Select brewer palette to use, see ?scales::brewer_pal for more details
d + scale_colour_brewer(type="seq")
d + scale_colour_brewer(type="seq", palette=3)

d + scale_colour_brewer(palette="Blues")
d + scale_colour_brewer(palette="Set1")

# scale_fill_brewer works just the same as
# scale_colour_brewer but for fill colours
ggplot(diamonds, aes(x=price, fill=cut)) +
  geom_histogram(position="dodge", binwidth=1000) +
  scale_fill_brewer()

# Generate map data
library(reshape2) # for melt
volcano3d <- melt(volcano)
names(volcano3d) <- c("x", "y", "z")

# Basic plot
v <- ggplot() + geom_tile(aes(x=x, y=y, fill=z), data=volcano3d)
v
v + scale_fill_distiller()
v + scale_fill_distiller(palette=2)
v + scale_fill_distiller(type="div")
v + scale_fill_distiller(palette="Spectral")
v + scale_fill_distiller(palette="Spectral", trans="reverse")
v + scale_fill_distiller(type="qual")
# Not appropriate for continuous data, issues a warning

shazhe/mvst0 documentation built on May 29, 2019, 9:20 p.m.