```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
```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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.