Skip to content

coatless-rpkg/paintr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

075e925 · Sep 13, 2024

History

37 Commits
Sep 13, 2024
Sep 13, 2024
Sep 13, 2024
Sep 13, 2024
Sep 13, 2024
Sep 13, 2024
Sep 13, 2024
Feb 8, 2024
Sep 13, 2024
Sep 13, 2024
Jan 10, 2024
Sep 13, 2024
Sep 13, 2024

Repository files navigation

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))