knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

vizoR

The goal of vizoR is to provide helper functions to help designing better visualizations in R.

Installation

This package is under active developpement. You can install it from github:

devtools::install_github("aneuraz/vizoR")

Palettes

Retrieving a color palette from color-hex.com (by number)

library(vizoR)

pal5361 <- color_hex_palette_from_number(5361)
pal5361

Plotting the palette

show_pal(pal5361)

Retrieving a color palette from color-hex.com (by name)

library(vizoR)

palCook <- color_hex_palette_from_name("Cook")
palCook
show_pal(palCook)

Retrieving a color palette from colourlovers.com (by number)

palTerra <- colour_lovers_palette_from_number("292482/Terra")
palTerra
show_pal(palTerra)

Using the palette

library(ggplot2)

p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(size = 4, aes(colour = factor(cyl))) +
  scale_color_manual(values = pal5361) +
  theme_bw()

Using a color-blind proof palette

Showing the palettes

library(patchwork) # devtools.install_github("thomasp85/patchwork")

p1 <- show_pal(cbp_pal(black = FALSE)(8))
p2 <- show_pal(cbp_pal(black = TRUE)(8))

p1 + p2 + patchwork::plot_layout(ncol = 1)

Using the palettes

p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(size = 4, aes(colour = factor(cyl))) +
  scale_color_cbp(black = FALSE) +
  theme_bw()

Generate random datasets for testing

dt <- generate_dataset_uniform(dataset_size = list(20,10, 15, 8), 
                               min_x = list(0, 1, 3, 3), 
                               max_x = list(3, 4, 5, 7), 
                               seed = 13)
dplyr::glimpse(dt)
p <- ggplot(dt, aes(x, y))
p + geom_point(size = 4, aes(colour = group)) +
  scale_color_cbp(black = FALSE) +
  theme_bw()

Themes

theme_elegant

p <- ggplot(dt, aes(x, y))
p + geom_point(size = 4, aes(colour = group)) +
  scale_color_cbp(black = FALSE) +
  theme_elegant()

theme_elegant_dark

p1 <- ggplot(dt, aes(x, y))
p1 + geom_point(size = 4, aes(colour = group)) +
  scale_color_cbp(black = FALSE) +
  theme_elegant_dark()


aneuraz/vizoR documentation built on Feb. 21, 2020, 2:43 p.m.