Examples for 'ggplot2::scale_colour_brewer'


Sequential, diverging and qualitative colour scales from ColorBrewer

Aliases: scale_colour_brewer scale_fill_brewer scale_colour_distiller scale_fill_distiller scale_colour_fermenter scale_fill_fermenter scale_color_brewer scale_color_distiller scale_color_fermenter

Keywords:

### ** Examples

dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
(d <- ggplot(dsamp, aes(carat, price)) +
  geom_point(aes(colour = clarity)))
plot of chunk example-ggplot2-scale_colour_brewer-1
d + scale_colour_brewer()
plot of chunk example-ggplot2-scale_colour_brewer-1
# Change scale label
d + scale_colour_brewer("Diamond\nclarity")
plot of chunk example-ggplot2-scale_colour_brewer-1
# Select brewer palette to use, see ?scales::brewer_pal for more details
d + scale_colour_brewer(palette = "Greens")
plot of chunk example-ggplot2-scale_colour_brewer-1
d + scale_colour_brewer(palette = "Set1")
plot of chunk example-ggplot2-scale_colour_brewer-1
## No test: 
# scale_fill_brewer works just the same as
# scale_colour_brewer but for fill colours
p <- ggplot(diamonds, aes(x = price, fill = cut)) +
  geom_histogram(position = "dodge", binwidth = 1000)
p + scale_fill_brewer()
plot of chunk example-ggplot2-scale_colour_brewer-1
# the order of colour can be reversed
p + scale_fill_brewer(direction = -1)
plot of chunk example-ggplot2-scale_colour_brewer-1
# the brewer scales look better on a darker background
p +
  scale_fill_brewer(direction = -1) +
  theme_dark()
plot of chunk example-ggplot2-scale_colour_brewer-1
## End(No test)

# Use distiller variant with continous data
v <- ggplot(faithfuld) +
  geom_tile(aes(waiting, eruptions, fill = density))
v
plot of chunk example-ggplot2-scale_colour_brewer-1
v + scale_fill_distiller()
plot of chunk example-ggplot2-scale_colour_brewer-1
v + scale_fill_distiller(palette = "Spectral")
plot of chunk example-ggplot2-scale_colour_brewer-1
# or use blender variants to discretise continuous data
v + scale_fill_fermenter()
plot of chunk example-ggplot2-scale_colour_brewer-1

[Package ggplot2 version 3.3.6 Index]