Skip to content

Latest commit

 

History

History
108 lines (77 loc) · 2.53 KB

README.md

File metadata and controls

108 lines (77 loc) · 2.53 KB

paintr

R-CMD-check

The goal of paintr is to draw different R data structures on graphs.

Note

A previous version of the package was called drawr; however, another package with the same name was published on CRAN. As a result, the package was renamed to paintr.

Installation

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

# install.packages("remotes")
remotes::install_github("coatless-rpkg/paintr")

Design

The package is designed to take advantage of base R graphics alongside ggplot2. We’re providing two different implementations for each system under the naming scheme of:

  • paint_*(): base R graphics
  • gpaint_*(): ggplot2

Example

Take for instance we have a matrix that looks like so:

mat_3x5 = matrix(
  c(
   1, NA,    3,   4,  NaN, 
  NA,  7,    8,  -9,  10, 
 -11, 12, -Inf, -14,  NA
 ),
 ncol = 5, byrow = TRUE)

mat_3x5
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1   NA    3    4  NaN
#> [2,]   NA    7    8   -9   10
#> [3,]  -11   12 -Inf  -14   NA

What if we wanted to see the contents laid out with their indices or specific cells highlighted?

# Load the library
library(paintr)

# Graphic of matrix data structure using base R graphics
paint_matrix(mat_3x5)

# Show the cell indices
paint_matrix(mat_3x5, show_indices = "cell")

# Show all indices
paint_matrix(mat_3x5, show_indices = "all")

# Highlight cells over a specific value
paint_matrix(mat_3x5, highlight_area = mat_3x5 > 4)

We can achieve similar results with the ggplot2 function.

# Graphic of matrix data structure using base R graphics
gpaint_matrix(mat_3x5)

# Highlight cells in specific columns
gpaint_matrix(mat_3x5, 
             show_indices = c("row", "column"),
             highlight_area = highlight_columns(mat_3x5, columns = 2:4))