Color Palettes - veeninglab/BactMAP GitHub Wiki

Almost all of BactMAP's plotting functions use the viridis color scale for heatmaps. In addition, the createPlotlist() function also recognizes a set of palettes inspired by the CUD colorblind-friendly palettes. How to view these palettes or add one palette manually is shown below. For discrete color scales, it is often possible to define your own colors in BactMAP's plotting functions.

Changing the color scale of BactMAP plots

In BactMAPs plotting functions, you can define the color or the color palette inside the plotting function. One way to change the color of your plot is to re-make it with the color or color palette defined inside the function. Check the documentation on this wiki for each function's color options!

However, sometimes it might be easier to change the color of your plot after you made the plot. This is also possible using the ggplot commands, for instance:

#for discrete scales:
myPlot_changedColors <- myPlot + scale_fill_brewer("Set1")

#for heatmap scales:
myHeatmap_changedColors <- myHeatmap + scale_fill_viridis("Magma")

There are many scales and options within ggplot2. Check options for heatmaps here and more general information about using colors in ggplot2 here.

Choosing discrete color scales

The CUD colorblind-friendly palette is saved in BactMAP. To get the hex codes of the CUD color palette, type the following command:

colorsCUD()

Choosing heatmap color scales

BactMAPs functions use the colorblind-friendly viridis palettes as a standard. However, for the cell projection heatmaps in createPlotlist(), a few more palettes inspired by the CUD palette are added. Below you can find the documentation of the functions to use these palettes and add your own palettes.

If you want to make your own continuous color scales, try http://gka.github.io/palettes .

Modify and view createPlotlist() palettes

Manually add a heatmap palette and view the currently loaded palettes.

Description

addPalette(): function to manually add a colorpalette for heatmaps to the six heatmap palettes existing inside bactMAP.

Use showCurrentPalettes() to print mockup-heatmap plots with the six default palettes and - if appliccable - the added palettes.

Usage

addPalette(palList = list("colorhex1", "colorhex2", "colorhex3")), palName = "YourPalette")

showCurrentPalettes()

Arguments

  • palList a list consisting of 3 hex color codes (character strings, for instance “#FFFFFF” or “#DD0088”) or color names known by R (for instance “red” or “violet”). Optional; if argument is not used, the function will ask for the colors seperately while running.

  • palName
    a character string defining the name of the added colorpalette. Optional, if argument not used, the function will ask for the palette name.

Value

addPalette() and showCurrentPalettes() will print heatmap plots using the color palettes loaded into bactMAP. addPalette() also adds the manually entered color palette to the list of color palettes loaded into the bactMAP environment during the R session.

References

The default color palettes are chosen based on the Color Universal Design (CUD, Masataka Okabe & Kei Ito): http://jfly.iam.u-tokyo.ac.jp/color/

Examples

##Check the color palettes 
showCurrentPalettes()

##Pick three colors you like and put them in a list - in the order of lowest value - midpoint - highest value
listofcolors <- list("orangered", "darkseagreen", "burlywood1")

##Add to the color palettes for createPlotlist()
addPalette(listofcolors, "MyBeautifulPalette")