Introduction
simplevis
provides gglot2
(and leaflet
) wrapper functions with an objective to help users make beautiful visualisation with less brainpower.
In the current post, we will discus the simplified and consistent method for colouring that simplevis has adopted.
Overview
In simplevis, users adhere to the following rules for adjusting colour:
- Always define the colours to use via the
pal
argument (short for palette) - If colouring by a variable, use a
*_col()
or*_col_facet()
function, and define thecol_var
- For
gg_sf_col*()
andgg_point_col*()
functions where thecol_var
is numeric, also define thecol_method
ofbin
orquantile
, and thecol_cuts
to use.
library(simplevis)
library(dplyr)
library(palmerpenguins)
1. Always define the colours to use via the pal
argument
The colour palette can be changed from the default viridis colours by providing a character vector of hex codes to the pal
argument.
gg_point(penguins, bill_length_mm, body_mass_g, pal = "#e7298a")
Users can get access to a large amount of colour palettes through the pals
package.
2. If colouring by a variable, use a *_col()
or *_col_facet()
function, and define the col_var
To colour by a variable, use a *_col()
function and then define that variable to be coloured using the col_var
argument.
gg_point_col(penguins, bill_length_mm, body_mass_g, species)
3. For gg_sf_col*()
and gg_point_col*()
functions where colouring by a numeric variable, also define the col_method
and col_cuts
All simplevis
*_col()
and *_col_facet()
functions support colouring by a categorical variable.
In addition, sf
and point
*_col()
and *_col_facet()
functions support colouring by a numeric variable.
You do this by specifying whether you want to do this by:
- defining whether the col_method is to be by
bin
orquantile
- defining a vector or col_cuts. These should be between 0 and infinity (
Inf
) forbin
and between 0 and 1 forquantile
plot_data <- ggplot2::diamonds %>%
slice_sample(prop = 0.01)
plot_data
#> # A tibble: 539 x 10
#> carat cut color clarity depth table price x y z
#> <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
#> 1 0.32 Ideal D SI2 59.5 57 477 4.47 4.5 2.67
#> 2 1.5 Premium D SI2 61.9 58 8649 7.34 7.27 4.52
#> 3 0.4 Premium D VS2 62.4 59 982 4.7 4.72 2.94
#> 4 2.01 Premium I SI2 63 59 9658 8.04 7.97 5.04
#> 5 0.51 Premium G VS2 61.1 58 1381 5.17 5.2 3.17
#> 6 0.41 Ideal D VS1 61.1 56 1427 4.8 4.83 2.94
#> 7 0.31 Ideal G VVS2 61.9 55 707 4.33 4.36 2.69
#> 8 0.61 Ideal H VS2 62.5 54 1591 5.43 5.45 3.4
#> 9 1.02 Premium G SI2 58.1 58 4078 6.67 6.58 3.85
#> 10 0.4 Ideal E SI2 61.9 58 629 4.71 4.73 2.92
#> # ... with 529 more rows
gg_point_col(plot_data,
x_var = carat,
y_var = price,
col_var = z,
col_method = "quantile",
col_cuts = c(0, 0.25, 0.5, 0.75, 1))
gg_point_col(plot_data,
x_var = carat,
y_var = price,
col_var = z,
col_method = "bin",
col_cuts = c(0, 1, 2, 3, 4, 5, Inf))