Visualization

Visualization is a central part of any data analysis pipeline. Ideally, you want to visualize data before and after all operations, if possible. Depending on the kind and amount of data you are working on, this can range from straightforward to rather challening, but it’s always worthwhile!
rtemis provides functions for static graphics - the mplot3 family of functions - as well as interactive graphics - the dplot3 family. The next two chapters cover static and interactive graphics, respectively. First, let’s look at the available color palettes and themes available to both sets of tools.

Color palettes

rtemis includes a number of builtin color palettes, along with a few functions to create, manipulate, and preview colors.

rtpalette()
02-23-24 13:56:18 The following palettes are available: [rtpalette]
 [1] "ucsfCol"             "pennCol"             "imperialCol"        
 [4] "stanfordCol"         "ucdCol"              "berkeleyCol"        
 [7] "ucscCol"             "ucmercedCol"         "ucsbCol"            
[10] "uclaCol"             "ucrColor"            "uciCol"             
[13] "ucsdCol"             "californiaCol"       "scrippsCol"         
[16] "caltechCol"          "cmuCol"              "princetonCol"       
[19] "columbiaCol"         "yaleCol"             "brownCol"           
[22] "cornellCol"          "hmsCol"              "dartmouthCol"       
[25] "usfCol"              "uwCol"               "jhuCol"             
[28] "nyuCol"              "washuCol"            "chicagoCol"         
[31] "pennstateCol"        "msuCol"              "michiganCol"        
[34] "iowaCol"             "texasCol"            "techCol"            
[37] "jeffersonCol"        "hawaiiCol"           "nihCol"             
[40] "torontoCol"          "mcgillCol"           "uclCol"             
[43] "oxfordCol"           "nhsCol"              "ethCol"             
[46] "rwthCol"             "firefoxCol"          "mozillaCol"         
[49] "appleCol"            "googleCol"           "amazonCol"          
[52] "microsoftCol"        "pantoneBalancingAct" "pantoneWellspring"  
[55] "pantoneAmusements"   "grays"               "rtCol1"             
[58] "rtCol3"             

Let’s use previewcolor() to look at a selection of the available palettes:

previewcolor(rtpalette("imperialCol"), "Imperial")

previewcolor(rtpalette("ucsfCol"), "UCSF")

previewcolor(rtpalette("pennCol"), "Penn")

previewcolor(rtpalette("stanfordCol"), "Stanford")

previewcolor(rtpalette("berkeleyCol"), "Berkeley")

previewcolor(rtpalette("scrippsCol"), "Scripps Research")

previewcolor(rtpalette("firefoxCol"), "Firefox")

Shown here with the darkgrayigrid theme, the default rtemis pallette is slightly pastel/desaturated and tries to provide good contrast between groups:

mplot3_x(iris)

Let’s try a different, rather recognizable, palette:

mplot3_x(iris, palette = "google")

Themes

The mplot3 and dplot3 families of functions support multiple different themes:

  • white
  • whitegrid
  • whiteigrid
  • black
  • blackgrid
  • blackigrid
  • darkgray
  • darkgraygrid
  • darkgrayigrid
  • lightgraygrid
  • mediumgraygrid
set.seed = 2019
x <- rnorm(200)
y <- x^3 + 12 + rnorm(200)
mplot3_xy(x, y, theme = 'white', fit = 'gam')

mplot3_xy(x, y, theme = 'whitegrid', fit = 'gam')

mplot3_xy(x, y, theme = 'whiteigrid', fit = 'gam')

mplot3_xy(x, y, theme = 'black', fit = 'gam')

mplot3_xy(x, y, theme = 'blackgrid', fit = 'gam')

mplot3_xy(x, y, theme = 'blackigrid', fit = 'gam')

mplot3_xy(x, y, theme = 'darkgray', fit = 'gam')

mplot3_xy(x, y, theme = 'darkgraygrid', fit = 'gam')

mplot3_xy(x, y, theme = 'darkgrayigrid', fit = 'gam')

mplot3_xy(x, y, theme = 'lightgraygrid', fit = 'gam')

mplot3_xy(x, y, theme = 'mediumgraygrid', fit = 'gam')

System Defaults

You can optionally set system defaults by running the following lines in R or adding them to your .Rprofile file, which is usually found in your home directory. For example, to default to the “darkgrayigrid” theme (works well with a dark VS Code or RStudio theme), you can use the following:

options(rt.theme = "darkgrayigrid")
options(rt.palette = "rtCol1")
options(rt.font = "Fira Sans")

The first line sets the theme for all mplot3/dplot3 functions that support it, and the second line defines the default palette, which works with both light and dark themes.