Skip to contents

Verify the integrity of the palettes object

Usage

verify_palettes(palettes, column_info, data)

Arguments

palettes

A named list of palettes. Each entry in column_info$palette should have an entry in this object. If an entry is missing, the type of the column will be inferred (categorical or numerical) and one of the default palettes will be applied. Alternatively, the name of one of the standard palette names can be used:

  • numerical: "Greys", "Blues", "Reds", "YlOrBr", "Greens"

  • categorical: "Set3", "Set1", "Set2", "Dark2"

column_info

A data frame describing which columns in data to plot. This data frame should contain the following columns:

  • id (character, required): A column name in data to plot. Determines the size of the resulting geoms, and also the color unless color is specified.

  • id_color (character): A column name in data to use for the color of the resulting geoms. If NA, the id column will be used.

  • id_size (character): A column name in data to use for the size of the resulting geoms. If NA, the id column will be used.

  • name (character): A label for the column. If NA or "", no label will be plotted. If this column is missing, id will be used to generate the name column.

  • geom (character): The geom of the column. Must be one of: "funkyrect", "circle", "rect", "bar", "pie", "text" or "image". For "text", the corresponding column in data must be a character. For "pie", the column must be a list of named numeric vectors. For all other geoms, the column must be a numeric.

  • group (character): The grouping id of each column, must match with column_groups$group. If this column is missing or all values are NA, columns are assumed not to be grouped.

  • palette (character): Which palette to colour the geom by. Each value should have a matching value in palettes$palette.

  • width: Custom width for this column (default: 1).

  • overlay: Whether to overlay this column over the previous column. If so, the width of that column will be inherited.

  • legend: Whether or not to add a legend for this column.

  • hjust: Horizontal alignment of the bar, must be between [0,1] (only for geom = "bar").

  • vjust: Vertical alignment of the label, must be between [0,1] (only for geom = "text").

  • size: Size of the label, must be a numeric value (only for geom = "text").

  • label: Which column to use as a label (only for geom = "text").

  • directory: Which directory to use to find the images (only for geom = "image").

  • extension: The extension of the images (only for geom = "image").

  • draw_outline: Whether or not to draw bounding guides (only for geom == "bar"). Default: TRUE.

  • options (list or json): Any of the options above. Any values in this column will be spread across the other columns. This is useful for not having to provide a data frame with 1000s of columns. This column can be a json string.

data

A data frame with items by row and features in the columns. Must contain one column named "id".

Value

The palettes object with all expected columns.

Examples

library(tibble)
library(grDevices)
library(RColorBrewer)

# explicit form
data <- tribble(
  ~id, ~name, ~x, ~y,
  "foo", "Foo", 0.5, 0.7,
  "bar", "Bar", 1.0, 0.1
)
column_info <- tribble(
  ~id, ~geom, ~palette,
  "name", "text", NA,
  "foo", "funkyrect", "pal1",
  "bar", "funkyrect", "pal2"
)
palettes <- list(
  pal1 = rev(brewer.pal(9, "Greys")[-1]),
  pal2 = rev(brewer.pal(9, "Reds")[-8:-9])
)
verify_palettes(palettes, column_info, data)
#> $pal1
#> [1] "#000000" "#252525" "#525252" "#737373" "#969696" "#BDBDBD" "#D9D9D9"
#> [8] "#F0F0F0"
#> 
#> $pal2
#> [1] "#CB181D" "#EF3B2C" "#FB6A4A" "#FC9272" "#FCBBA1" "#FEE0D2" "#FFF5F0"
#> 

# implicit palettes
palettes <- list(
  pal1 = "Greys",
  pal2 = "Reds"
)
verify_palettes(palettes, column_info, data)
#> $pal1
#>   [1] "#000000" "#020202" "#050505" "#070707" "#0A0A0A" "#0C0C0C" "#0F0F0F"
#>   [8] "#121212" "#141414" "#171717" "#191919" "#1C1C1C" "#1F1F1F" "#212121"
#>  [15] "#242424" "#272727" "#2A2A2A" "#2D2D2D" "#303030" "#333333" "#373737"
#>  [22] "#3A3A3A" "#3D3D3D" "#404040" "#434343" "#464646" "#494949" "#4D4D4D"
#>  [29] "#505050" "#525252" "#555555" "#575757" "#595959" "#5C5C5C" "#5E5E5E"
#>  [36] "#606060" "#636363" "#656565" "#676767" "#6A6A6A" "#6C6C6C" "#6E6E6E"
#>  [43] "#717171" "#737373" "#757575" "#787878" "#7A7A7A" "#7D7D7D" "#7F7F7F"
#>  [50] "#828282" "#848484" "#868686" "#898989" "#8B8B8B" "#8E8E8E" "#909090"
#>  [57] "#939393" "#959595" "#989898" "#9B9B9B" "#9D9D9D" "#A0A0A0" "#A3A3A3"
#>  [64] "#A5A5A5" "#A8A8A8" "#ABABAB" "#AEAEAE" "#B0B0B0" "#B3B3B3" "#B6B6B6"
#>  [71] "#B9B9B9" "#BBBBBB" "#BEBEBE" "#C0C0C0" "#C2C2C2" "#C4C4C4" "#C5C5C5"
#>  [78] "#C7C7C7" "#C9C9C9" "#CBCBCB" "#CDCDCD" "#CFCFCF" "#D1D1D1" "#D3D3D3"
#>  [85] "#D5D5D5" "#D7D7D7" "#D9D9D9" "#DBDBDB" "#DCDCDC" "#DEDEDE" "#DFDFDF"
#>  [92] "#E1E1E1" "#E3E3E3" "#E4E4E4" "#E6E6E6" "#E7E7E7" "#E9E9E9" "#EBEBEB"
#>  [99] "#ECECEC" "#EEEEEE" "#F0F0F0"
#> 
#> $pal2
#>   [1] "#CB181D" "#CD1A1D" "#CF1C1E" "#D11E1F" "#D32020" "#D52221" "#D72422"
#>   [8] "#DA2623" "#DC2824" "#DE2A25" "#E02D26" "#E22F26" "#E43127" "#E73328"
#>  [15] "#E93529" "#EB372A" "#ED392B" "#EF3B2C" "#EF3E2E" "#F04130" "#F14432"
#>  [22] "#F24733" "#F24A35" "#F34C37" "#F44F39" "#F5523B" "#F5553C" "#F6583E"
#>  [29] "#F75A40" "#F75D42" "#F86044" "#F96345" "#FA6647" "#FA6949" "#FB6B4B"
#>  [36] "#FB6E4E" "#FB7050" "#FB7252" "#FB7555" "#FB7757" "#FB7A5A" "#FB7C5C"
#>  [43] "#FB7E5E" "#FB8161" "#FB8363" "#FB8666" "#FB8868" "#FB8A6A" "#FB8D6D"
#>  [50] "#FB8F6F" "#FC9272" "#FC9474" "#FC9677" "#FC997A" "#FC9B7D" "#FC9E80"
#>  [57] "#FCA082" "#FCA385" "#FCA588" "#FCA88B" "#FCAA8E" "#FCAD91" "#FCAF93"
#>  [64] "#FCB196" "#FCB499" "#FCB69C" "#FCB99F" "#FCBBA1" "#FCBDA4" "#FCC0A7"
#>  [71] "#FCC2AA" "#FCC4AD" "#FCC6B0" "#FCC9B3" "#FCCBB6" "#FDCDB9" "#FDCFBC"
#>  [78] "#FDD1BF" "#FDD4C2" "#FDD6C5" "#FDD8C8" "#FDDACB" "#FDDDCE" "#FDDFD1"
#>  [85] "#FEE0D3" "#FEE2D5" "#FEE3D6" "#FEE4D8" "#FEE5DA" "#FEE7DC" "#FEE8DE"
#>  [92] "#FEE9DF" "#FEEAE1" "#FEECE3" "#FEEDE5" "#FEEEE7" "#FEEFE8" "#FEF1EA"
#>  [99] "#FEF2EC" "#FEF3EE" "#FFF5F0"
#> 

# passing a tibble should also work (for backwards compatibility)
palettes <- tribble(
  ~palette, ~colours,
  "pal1", rev(brewer.pal(9, "Greys")[-1]),
  "pal2", rev(brewer.pal(9, "Reds")[-8:-9])
)
verify_palettes(palettes, column_info, data)
#> $pal1
#> [1] "#000000" "#252525" "#525252" "#737373" "#969696" "#BDBDBD" "#D9D9D9"
#> [8] "#F0F0F0"
#> 
#> $pal2
#> [1] "#CB181D" "#EF3B2C" "#FB6A4A" "#FC9272" "#FCBBA1" "#FEE0D2" "#FFF5F0"
#>