scale_colour_gradient: Scale color continuous with SGB-colors

Description Usage Arguments See Also Examples

View source: R/scales.R

Description

Overwrites the default continuous color scale with SGB-colors. To use another palette or custom colours, use scale_color_gradient().

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

Arguments

...

parameters passed on to scale_color_gradient().

low, high

Colours for low and high end of the gradient

mid

Colour for mid point

colors, colours

Vector of colours to use for n-colour gradient.

See Also

Other colour scales: scale_colour_discrete(), scale_fill_discrete(), scale_fill_gradient()

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## Not run: 
library(ggplot2)
library(gsgb)
theme_set(theme_sgb(base_size = 9))

ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length))

# This gives the same:
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length)) +
  scale_color_gradient()

# Custom gradient colors:
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length)) +
  scale_color_gradient(low = pal_sgb_dunkelblau[5], high = pal_sgb_gelb[5])

# 3-color gradient (default):
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length)) +
  scale_color_gradient2(midpoint = 6)

# 3-color gradient (custom):
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length)) +
  scale_color_gradient2(low = pal_sgb_rot[5], mid = "white", high = pal_sgb_gelb[5],
                        midpoint = 6)

# n-color gradient (default):
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length)) +
  scale_color_gradientn()

# n-color gradient (custom):
ggplot(iris, aes(Sepal.Width, Sepal.Length)) +
  geom_point(aes(color = Sepal.Length)) +
  scale_color_gradientn(colors = pal_sgb_pref)

# Use `na.value = NA` to hide missing values but keep the original axis range
df_na <- data.frame(
  value = seq(1, 20),
  x = runif(20),
  y = runif(20),
  z1 = c(rep(NA, 10), rnorm(10)))

ggplot(df_na, aes(x = value, y)) +
  geom_point(aes(color = z1)) +
  scale_color_gradient(na.value = NA)

# or select custom color for missing values
ggplot(df_na, aes(x = value, y)) +
  geom_point(aes(color = z1)) +
  scale_color_gradient(na.value = SGBdunkelblau)

## End(Not run)

SchweizerischerGewerkschaftsbund/gsgb documentation built on Dec. 18, 2021, 1 p.m.