Continuous variable

```r}-point-gradient, fig.cap = "Coloured along a continuous variable."} ggplot(diamonds, aes(x = carat, y = depth, colour = price)) + geom_point() + scale_colour_gradient()

\FloatBarrier

```r}-tile-gradient2, fig.cap = "Coloured along a continuous variable using a gradient with midpoint."}
ggplot(diamonds, aes(x = carat, y = depth, colour = price)) +
  geom_point() +
  scale_colour_gradient2(midpoint = 1e4)

\FloatBarrier

Ordinal variable

```r}-histogram-oridinal, fig.cap = "Coloured along an ordinal variable."} ggplot(diamonds, aes(x = carat, y = depth, colour = cut)) + geom_point()

\FloatBarrier

## Categorical variable

Here we illustrate figures with a different number of categories.
We choose for scatter plots with random x, y and category.
This is the most difficult situation to distinguish the colours.
Be careful when you use more than 5 colours.

```r}-categorical-2, fig.cap = "Coloured by a two level categorical variable."}
data.frame(
  x = runif(1e3), y = runif(1e3),
  category = sample(LETTERS[1:2], 1e3, replace = TRUE)
) |>
  ggplot(aes(x = x, y = y, colour = category)) +
  geom_jitter()

\FloatBarrier

```r}-categorical-3, fig.cap = "Coloured by a three level categorical variable."} data.frame( x = runif(1e3), y = runif(1e3), category = sample(LETTERS[1:3], 1e3, replace = TRUE) ) |> ggplot(aes(x = x, y = y, colour = category)) + geom_jitter()

\FloatBarrier

```r}-categorical-4, fig.cap = "Coloured by a four level categorical variable."}
data.frame(
  x = runif(1e3), y = runif(1e3),
  category = sample(LETTERS[1:4], 1e3, replace = TRUE)
) |>
  ggplot(aes(x = x, y = y, colour = category)) +
  geom_jitter()

\FloatBarrier

```r}-categorical-5, fig.cap = "Coloured by a five level categorical variable."} data.frame( x = runif(1e3), y = runif(1e3), category = sample(LETTERS[1:5], 1e3, replace = TRUE) ) |> ggplot(aes(x = x, y = y, colour = category)) + geom_jitter()

\FloatBarrier

```r}-categorical-6, fig.cap = "Coloured by a six level categorical variable."}
data.frame(
  x = runif(1e3), y = runif(1e3),
  category = sample(LETTERS[1:6], 1e3, replace = TRUE)
) |>
  ggplot(aes(x = x, y = y, colour = category)) +
  geom_jitter()

\FloatBarrier

```r}-categorical-7, fig.cap = "Coloured by a seven level categorical variable."} data.frame( x = runif(1e3), y = runif(1e3), category = sample(LETTERS[1:7], 1e3, replace = TRUE) ) |> ggplot(aes(x = x, y = y, colour = category)) + geom_jitter()

\FloatBarrier

```r}-categorical-8, fig.cap = "Coloured by an eight level categorical variable."}
data.frame(
  x = runif(1e3), y = runif(1e3),
  category = sample(LETTERS[1:8], 1e3, replace = TRUE)
) |>
  ggplot(aes(x = x, y = y, colour = category)) +
  geom_jitter()

\FloatBarrier



inbo/INBOtheme documentation built on April 6, 2023, 5:09 a.m.