An open API service indexing awesome lists of open source software.

https://github.com/coatless-rpkg/paintr

Draw different R data structures on graphs
https://github.com/coatless-rpkg/paintr

data-structures draw paint r-package rstats

Last synced: 6 months ago
JSON representation

Draw different R data structures on graphs

Awesome Lists containing this project

README

        

---
output:
github_document
#fig_width: 7
#fig_height: 5 # default is 5
---

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

# paintr

[![R-CMD-check](https://github.com/coatless-rpkg/paintr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/coatless-rpkg/paintr/actions/workflows/R-CMD-check.yaml)

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](https://github.com/) with:

``` r
# 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:

```{r}
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
```

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

```{r}
#| label: base-example
#| results: 'markup'
# 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.

```{r}
#| label: ggplot2-example
#| results: 'markup'
# 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))
```