Official Lego Color Palettes

Provides a dataset containing several color naming conventions established by multiple sources, along with associated color metadata. The package also provides related helper functions for mapping among the different Lego color naming conventions and between Lego colors, hex colors, and 'R' color names, making it easy to convert any color palette to one based on existing Lego colors while keeping as close to the original color palette as possible. The functions use nearest color matching based on Euclidean distance in RGB space. Naming conventions for color mapping include those from 'BrickLink' (<>), 'The Lego Group' (<>), 'LDraw' (<>), and 'Peeron' (<>).


Author: Matthew Leonawicz
License: MIT
CRAN status CRAN downloads Rdoc Travis build status AppVeyor build status Codecov test coverage

legocolors provides a dataset containing several Lego color naming conventions established by various popular sources. It also provides functions for mapping between these color naming conventions as well as between Lego color names, hex colors, and R color names.

By default, nearest colors are computed based on distance in RGB space when an exact match is not found. This behavior supports the purpose of exchanging arbitrary colors for known Lego colors when the goal is to actually acquire and build something out of Lego parts. This focus is also one of the reasons legocolors uses BrickLink color names as the default naming convention. See ?legocolor for details.


You can install the released version of legocolors from CRAN with:


You can install the development version of legocolors from GitHub with:


Palette conversions

The key helper functions are hex_to_legocolor and legocolor_to_hex. hex_to_color is also provided for general convenience.

hex_to_color(c("#ff0000", "#ff0001"))
#> [1] "red"  "~red"
#> [1] "~Trans-Red"
hex_to_legocolor("#ff0000", material = "solid")
#> [1] "~Red"
#> [1] "#B40000"
#> [1] "~red3"
x <- topo.colors(10)
#>  [1] "~Dark Purple"              "~Blue"                    
#>  [3] "~Trans-Dark Blue"          "~Medium Azure"            
#>  [5] "~Bright Green"             "~Lime"                    
#>  [7] "~Glitter Trans-Neon Green" "~Trans-Yellow"            
#>  [9] "~Trans-Neon Green"         "~Light Flesh"
hex_to_legocolor(x, material = "solid")
#>  [1] "~Dark Purple"         "~Blue"                "~Dark Azure"         
#>  [4] "~Medium Azure"        "~Bright Green"        "~Lime"               
#>  [7] "~Yellow"              "~Yellow"              "~Bright Light Yellow"
#> [10] "~Light Flesh"
hex_to_legocolor(x, def = "tlg", material = "solid")
#>  [1] "~Medium Lilac"           "~Bright Blue"           
#>  [3] "~Dark Azur"              "~Medium Azur"           
#>  [5] "~Bright Green"           "~Bright Yellowish Green"
#>  [7] "~Bright Yellow"          "~Bright Yellow"         
#>  [9] "~Cool Yellow"            "~Light Nougat"

While different sets of Lego colors are organized by material type, e.g., solid colors, semi-transparent colors, etc., these palettes are not useful for plotting data. The greatest value comes from converting useful color palettes to those comprised of existing Lego colors while still keeping as close to the original palette as possible.

Palette preview

The view_legopal function can be used to quickly see a Lego color palette. It can plot a named material palette, but like the functions above, it can also display a converted palette if given an arbitrary vector of hex color values.

r <- rainbow(9)
#> [1] "#FF0000FF" "#FFAA00FF" "#AAFF00FF" "#00FF00FF" "#00FFAAFF" "#00AAFFFF"
#> [7] "#0000FFFF" "#AA00FFFF" "#FF00AAFF"
view_legopal(r, material = "solid", show_labels = TRUE, label_size = 0.7)

Recommended colors

Filtering to a decent set of Lego colors that are relatively easy to acquire online at for simple brick and/or plate parts can be done using the recommended column in the legocolors dataset. This logical column is originally derived using the following criteria:

rec <- arrange(legocolors, desc(bl_bp)) %>%
  filter( & material == "solid" & bl_bp > 0.1) %>%
  select(bl_name, bl_bp)
#> # A tibble: 36 x 2
#>    bl_name           bl_bp
#>    <chr>             <dbl>
#>  1 White             1    
#>  2 Black             0.962
#>  3 Light Bluish Gray 0.927
#>  4 Red               0.912
#>  5 Dark Bluish Gray  0.896
#>  6 Tan               0.851
#>  7 Blue              0.803
#>  8 Yellow            0.797
#>  9 Reddish Brown     0.731
#> 10 Green             0.679
#> # ... with 26 more rows
filter(legocolors, recommended & !$hex %>%
  view_legopal(show_labels = TRUE, label_size = 0.5)

The bl_bp column provides a rough estimate of the relative availability of simple bricks and/or plates in a particular color for sale worldwide on BrickLink, scaled between 0 and 1. This is only computed when the package is updated, but these values should not fluctuate wildly. The metric used is also not perfect, but it will at least provide a much more reasonable set of colors in terms of reasonably obtainable bricks and plates.

You can use the variables in legocolors differently to derive your own subset of colors that are relatively acquirable. This is worth considering because even though BrickLink consistently offers the widest selection and greatest quantity at the lowest price, supply and demand leads to some parts in some colors being prohibitively expensive to acquire in quantity. When determining what colors you wish to use to build a physical model, you will save an incredible amount of money if you can accept limiting your palette to the most common Lego colors.

The rough metric used here represents an initial step at avoiding Lego color palettes containing the more exotic, difficult to acquire colors, or colors which are only used in specialty parts that may not be amenable to general building with basic bricks and plates.


legocolors 0.2.0

  • Added view_legopal function.
  • Added new columns bl_bp (rough BrickLink brick/plate availability metric) and recommended (recommended colors, based on relative ease of acquirement) to the legocolors dataset.
  • Documentation updates.

legocolors 0.1.2

  • Additional formatting fix.

legocolors 0.1.1

  • Added formatting updates to DESCRIPTION and included relevant URLs.

legocolors 0.1.0

  • Added initial package scaffolding
  • Added initial package version data, functions and documentation.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.2.0 by Matthew Leonawicz, a year ago

Report a bug at

Browse source code at

Authors: Matthew Leonawicz [aut, cre]

Documentation:   PDF Manual  

MIT + file LICENSE license

Suggests testthat, covr

See at CRAN