bsscol allows for a simple integration of the BSS base colors into ggplot2 and alike.
You can install the released version of bsscol from Github with:
library(devtools) # install devtool first if not installed
install_github("qwertzlbry/bsscol")
Or just copy the package folder from: “G:/BSS/Administration/05_BSS_Vorlagen/Farben_R_Stata/bsscol” into your local R library and load it.
With a future CRAN approval the package could be installed with:
install.packages("bsscol") # currently the installation works only over github
In order to run the following examples you’ll also need:
install.packages("ggplot2")
install.packages("plotrix")
install.packages("dplyr")
install.packages("hues")
install.packages("ggthemes")
install.packages("DT")
install.packages("kableExtra")
library(bsscol)
library(ggplot2)
library(plotrix)
library(hues)
library(ggthemes)
library(dplyr, warn.conflicts=F, quietly=T)
library(kableExtra, warn.conflicts=F, quietly=T)
The following table contains all the BSS colors. When the package is
loaded this table can be called with the bss_colors
command.
| R | G | B | hex | Typ | Full | col_pal | hashed_hex | excel_form | name | | :-- | :-- | :-- | :----- | ---: | :---------- | -------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------: | :-------- | | 255 | 255 | 255 | FFFFFF | 0 | 255,255,255 | 1 | #FFFFFF | 1 | weiss | | 242 | 242 | 242 | F2F2F2 | -5 | 242,242,242 | 1 | #F2F2F2 | 11 | NA | | 217 | 217 | 217 | D9D9D9 | -15 | 217,217,217 | 1 | #D9D9D9 | 21 | NA | | 191 | 191 | 191 | BFBFBF | -25 | 191,191,191 | 1 | #BFBFBF | 31 | NA | | 166 | 166 | 166 | A6A6A6 | -35 | 166,166,166 | 1 | #A6A6A6 | 41 | NA | | 128 | 128 | 128 | 808080 | -50 | 128,128,128 | 1 | #808080 | 51 | NA | | 0 | 0 | 0 | 000000 | 0 | 0,0,0 | 2 | #000000 | 2 | schwarz | | 128 | 128 | 128 | 808080 | 50 | 128,128,128 | 2 | #808080 | 12 | NA | | 89 | 89 | 89 | 595959 | 35 | 89,89,89 | 2 | #595959 | 22 | NA | | 64 | 64 | 64 | 404040 | 25 | 64,64,64 | 2 | #404040 | 32 | NA | | 38 | 38 | 38 | 262626 | 15 | 38,38,38 | 2 | #262626 | 42 | NA | | 13 | 13 | 13 | 0D0D0D | 5 | 13,13,13 | 2 | #0D0D0D | 52 | NA | | 242 | 242 | 242 | F2F2F2 | 0 | 242,242,242 | 3 | #F2F2F2 | 3 | hellgrau1 | | 218 | 218 | 218 | DADADA | -10 | 218,218,218 | 3 | #DADADA | 13 | NA | | 182 | 182 | 182 | B6B6B6 | -25 | 182,182,182 | 3 | #B6B6B6 | 23 | NA | | 121 | 121 | 121 | 797979 | -50 | 121,121,121 | 3 | #797979 | 33 | NA | | 61 | 61 | 61 | 3D3D3D | -75 | 61,61,61 | 3 | #3D3D3D | 43 | NA | | 23 | 23 | 23 | 171717 | -90 | 23,23,23 | 3 | #171717 | 53 | NA | | 191 | 191 | 191 | BFBFBF | 0 | 191,191,191 | 4 | #BFBFBF | 4 | grau | | 242 | 242 | 242 | F2F2F2 | 80 | 242,242,242 | 4 | #F2F2F2 | 14 | NA | | 230 | 230 | 230 | E6E6E6 | 60 | 230,230,230 | 4 | #E6E6E6 | 24 | NA | | 217 | 217 | 217 | D9D9D9 | 40 | 217,217,217 | 4 | #D9D9D9 | 34 | NA | | 143 | 143 | 143 | 8F8F8F | -25 | 143,143,143 | 4 | #8F8F8F | 44 | NA | | 96 | 96 | 96 | 606060 | -50 | 96,96,96 | 4 | #606060 | 54 | NA | | 21 | 95 | 144 | 155F90 | 0 | 21,95,144 | 5 | #155F90 | 5 | blau | | 193 | 225 | 247 | C1E1F7 | 80 | 193,225,247 | 5 | #C1E1F7 | 15 | NA | | 135 | 197 | 237 | 87C5ED | 60 | 135,197,237 | 5 | #87C5ED | 25 | NA | | 73 | 167 | 228 | 49A7E4 | 40 | 73,167,228 | 5 | #49A7E4 | 35 | NA | | 16 | 71 | 107 | 10476B | -25 | 16,71,107 | 5 | #10476B | 45 | NA | | 11 | 48 | 72 | 0B3048 | -50 | 11,48,72 | 5 | #0B3048 | 55 | NA | | 171 | 228 | 65 | ABE441 | 0 | 171,228,65 | 6 | #ABE441 | 6 | grün | | 238 | 250 | 216 | EEFAD8 | 80 | 238,250,216 | 6 | #EEFAD8 | 16 | NA | | 221 | 244 | 179 | DDF4B3 | 60 | 221,244,179 | 6 | #DDF4B3 | 26 | NA | | 204 | 238 | 140 | CCEE8C | 40 | 204,238,140 | 6 | #CCEE8C | 36 | NA | | 134 | 191 | 28 | 86BF1C | -25 | 134,191,28 | 6 | #86BF1C | 46 | NA | | 90 | 129 | 18 | 5A8112 | -50 | 90,129,18 | 6 | #5A8112 | 56 | NA | | 229 | 35 | 61 | E5233D | 0 | 229,35,61 | 7 | #E5233D | 7 | rot | | 250 | 209 | 215 | FAD1D7 | 80 | 250,209,215 | 7 | #FAD1D7 | 17 | NA | | 244 | 166 | 175 | F4A6AF | 60 | 244,166,175 | 7 | #F4A6AF | 27 | NA | | 239 | 122 | 137 | EF7A89 | 40 | 239,122,137 | 7 | #EF7A89 | 37 | NA | | 176 | 21 | 40 | B01528 | -25 | 176,21,40 | 7 | #B01528 | 47 | NA | | 118 | 14 | 27 | 760E1B | -50 | 118,14,27 | 7 | #760E1B | 57 | NA | | 238 | 236 | 34 | EEEC22 | 0 | 238,236,34 | 8 | #EEEC22 | 8 | gelb | | 252 | 252 | 209 | FCFCD1 | 80 | 252,252,209 | 8 | #FCFCD1 | 18 | NA | | 249 | 249 | 166 | F9F9A6 | 60 | 249,249,166 | 8 | #F9F9A6 | 28 | NA | | 244 | 244 | 121 | F4F479 | 40 | 244,244,121 | 8 | #F4F479 | 38 | NA | | 189 | 189 | 15 | BDBD0F | -25 | 189,189,15 | 8 | #BDBD0F | 48 | NA | | 126 | 126 | 10 | 7E7E0A | -50 | 126,126,10 | 8 | #7E7E0A | 58 | NA | | 107 | 197 | 255 | 6BC5FF | 0 | 107,197,255 | 9 | #6BC5FF | 9 | hellblau | | 225 | 243 | 255 | E1F3FF | 80 | 225,243,255 | 9 | #E1F3FF | 19 | NA | | 196 | 232 | 255 | C4E8FF | 60 | 196,232,255 | 9 | #C4E8FF | 29 | NA | | 166 | 219 | 255 | A6DBFF | 40 | 166,219,255 | 9 | #A6DBFF | 39 | NA | | 15 | 159 | 255 | 0F9FFF | -25 | 15,159,255 | 9 | #0F9FFF | 49 | NA | | 0 | 108 | 181 | 006CB5 | -50 | 0,108,181 | 9 | #006CB5 | 59 | NA | | 237 | 246 | 249 | EDF6F9 | 0 | 237,246,249 | 10 | #EDF6F9 | 10 | hellgrau2 | | 201 | 228 | 237 | C9E4ED | -10 | 201,228,237 | 10 | #C9E4ED | 20 | NA | | 146 | 200 | 218 | 92C8DA | -25 | 146,200,218 | 10 | #92C8DA | 30 | NA | | 61 | 152 | 182 | 3D98B6 | -50 | 61,152,182 | 10 | #3D98B6 | 40 | NA | | 30 | 77 | 91 | 1E4D5B | -75 | 30,77,91 | 10 | #1E4D5B | 50 | NA | | 12 | 30 | 35 | 0C1E23 | -90 | 12,30,35 | 10 | #0C1E23 | 60 | NA |
Filtering the table by e.g. palettes (col_pal)
The following diagram contains all basic bss colors. They are stored in
a vector with the corresponding names. Unlike to the bss_colors table,
these colors can therefore be called in functions by their names. When
the package is loaded the vector can be called with the basic_colors
command. However, the basic bss colors can also be found in the bigger
above shown bss_colors table, as it includes all colors.
basic_colors
#> weiss schwarz hellgrau1 grau blau grün rot gelb
#> "#FFFFFF" "#000000" "#F2F2F2" "#BFBFBF" "#155F90" "#ABE441" "#E5233D" "#EEEC22"
#> hellblau hellgrau2
#> "#6BC5FF" "#EDF6F9"
The bss_cols function allows you to get and reference hex colors in a robust and flexible way for the basic_colors. As you can see in the example below, I am calling the colors by their names. Hence, this function does not work with the hex codes of the big, above showed bss_colors table.
# to get the basic colors
bss_cols()
#> weiss schwarz hellgrau1 grau blau grün rot gelb
#> "#FFFFFF" "#000000" "#F2F2F2" "#BFBFBF" "#155F90" "#ABE441" "#E5233D" "#EEEC22"
#> hellblau hellgrau2
#> "#6BC5FF" "#EDF6F9"
# to get the information of a color
bss_cols("rot")
#> rot
#> "#E5233D"
# or to just use a color in a plot
ggplot(mtcars, aes(hp, mpg)) +
geom_point(color = bss_cols("rot"),
size = 2, alpha = .8)+
theme_hc()
With the command bss_palettes
you can see all the coded palettes
stored in a list.
# the following subset color palettes are available
bss_palettes
#> $monochrome_black1
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#808080" "#A6A6A6" "#BFBFBF" "#D9D9D9" "#F2F2F2" "#FFFFFF"
#>
#> $black_yellow
#> [1] "#808080" "#A6A6A6" "#BFBFBF" "#D9D9D9" "#F2F2F2" "#FFFFFF" "#FCFCD1"
#> [8] "#F9F9A6" "#F4F479" "#EEEC22" "#BDBD0F" "#7E7E0A"
#>
#> $black_red
#> [1] "#808080" "#A6A6A6" "#BFBFBF" "#D9D9D9" "#F2F2F2" "#FFFFFF" "#FAD1D7"
#> [8] "#F4A6AF" "#EF7A89" "#E5233D" "#B01528" "#760E1B"
#>
#> $black_green
#> [1] "#808080" "#A6A6A6" "#BFBFBF" "#D9D9D9" "#F2F2F2" "#FFFFFF" "#EEFAD8"
#> [8] "#DDF4B3" "#CCEE8C" "#ABE441" "#86BF1C" "#5A8112"
#>
#> $monochrome_green
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#5A8112" "#86BF1C" "#ABE441" "#CCEE8C" "#DDF4B3" "#EEFAD8"
#>
#> $monochrome_red
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#760E1B" "#B01528" "#E5233D" "#EF7A89" "#F4A6AF" "#FAD1D7"
#>
#> $red_green
#> [1] "#760E1B" "#B01528" "#E5233D" "#EF7A89" "#FFFFFF" "#CCEE8C" "#ABE441"
#> [8] "#86BF1C" "#5A8112"
#>
#> $red_yellow
#> [1] "#760E1B" "#B01528" "#E5233D" "#EF7A89" "#F4A6AF" "#FAD1D7" "#FCFCD1"
#> [8] "#F9F9A6" "#F4F479" "#EEEC22" "#BDBD0F" "#7E7E0A"
#>
#> $monochrome_yellow
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#7E7E0A" "#BDBD0F" "#EEEC22" "#F4F479" "#F9F9A6" "#FCFCD1"
#>
#> $monochrome_blue
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#006CB5" "#0F9FFF" "#6BC5FF" "#A6DBFF" "#C4E8FF" "#E1F3FF"
#>
#> $blue_yellow
#> [1] "#006CB5" "#0F9FFF" "#6BC5FF" "#A6DBFF" "#C4E8FF" "#E1F3FF" "#FCFCD1"
#> [8] "#F9F9A6" "#F4F479" "#EEEC22" "#BDBD0F" "#7E7E0A"
#>
#> $blue_green
#> [1] "#006CB5" "#0F9FFF" "#6BC5FF" "#A6DBFF" "#C4E8FF" "#E1F3FF" "#EEFAD8"
#> [8] "#DDF4B3" "#CCEE8C" "#ABE441" "#86BF1C" "#5A8112"
#>
#> $blue_red
#> [1] "#006CB5" "#0F9FFF" "#6BC5FF" "#A6DBFF" "#C4E8FF" "#E1F3FF" "#FAD1D7"
#> [8] "#F4A6AF" "#EF7A89" "#E5233D" "#B01528" "#760E1B"
#>
#> $main
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#FFFFFF" "#000000" "#F2F2F2" "#BFBFBF" "#155F90" "#ABE441"
#> [,7] [,8] [,9] [,10]
#> hashed_hex "#E5233D" "#EEEC22" "#6BC5FF" "#EDF6F9"
#>
#> $main_only_color
#> [,1] [,2] [,3] [,4] [,5]
#> hashed_hex "#155F90" "#ABE441" "#E5233D" "#EEEC22" "#6BC5FF"
#>
#> $triple_cols
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> hashed_hex "#FFFFFF" "#000000" "#BFBFBF" "#F2F2F2" "#D9D9D9" "#155F90"
#> [,7] [,8] [,9] [,10] [,11] [,12]
#> hashed_hex "#C1E1F7" "#49A7E4" "#ABE441" "#EEFAD8" "#CCEE8C" "#E5233D"
#> [,13] [,14] [,15] [,16] [,17]
#> hashed_hex "#FAD1D7" "#EF7A89" "#EEEC22" "#FCFCD1" "#F4F479"
#e.g.
swatch(bss_palettes$red_green)
The function
bss_pal()
allows to interpolate the palette colors for a certain
number of levels, making it possible to create shades between the
original colors using colorRampPalette from grDevices. This command can
be used to extend to numbers of colors in a palette, however the hex
codes of some color shades can then deviate from the above bss_colors
table. Therefore, I recommend to use the coded palettes mentioned above,
if possible.
# interpolate the "main_only_color" palette (which only includes five colors) to a length of 20:
bss_pal("main_only_color")(20)
#> [1] "#155F90" "#347B7F" "#54976E" "#73B35E" "#93CF4D" "#AED940" "#BAB13F"
#> [8] "#C6883F" "#D25F3E" "#DE373D" "#E5383A" "#E76234" "#E98C2E" "#EBB729"
#> [15] "#EDE123" "#D9E544" "#BDDD73" "#A2D5A1" "#86CDD0" "#6BC5FF"
The function bss_pal
gets a palette by name from the list above
(“main_only_color” by default) and has a boolean condition
(rev =T/F
) determining whether to reverse the order of colors or not.
# Example of pie chart extending monochrome_yellow palettes to 50 shades.
pie3D(rep(5, 50),explode=0, theta=1.2, col=bss_pal(rev = T,"monochrome_yellow")(50),main="bss_pal('monochrome_yellow')(50)")
scale_color_bss()
is a custom color scale function for ggplot2 plots.
The same could also be achieved with the function scale_colour_manual
of the ggplot2 package. However, the usage of the bsscol palettes makes
this process more tidy and efficient. In the function two boolean
parameters discrete = T/F, reverse = T/F
can be choosen.
# Color by discrete variable using default palette main_only_color
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Species)) +
geom_point(size = 2) +
scale_color_bss() +
theme_hc()
# Color by numeric variable with monochrome_red palette
ggplot(iris, aes(Sepal.Width, Sepal.Length, color = Sepal.Length)) +
geom_point(size = 2, alpha = .6) +
scale_color_bss(discrete = FALSE, palette = "monochrome_red")+
theme_hc()
scale_fill_bss()
is a custom fill scale function for ggplot2 plots.
The same could also be achieved with the function scale_fill_manual
of
the ggplot2 package. However, the usage of the bsscol palettes makes
this process more tidy and efficient. The shades of colors are
automatically extended when using more colors than a standard palettes
has to offer. In the function two boolean parameters
discrete = T/F, reverse = T/F
can be chosen.
# Fill by discrete variable with the main palette + remove legend (guide)
ggplot(mpg, aes(model , fill = model )) +
geom_bar() +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_fill_bss(palette = "main", guide = "none")+
theme_hc()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.