Skip to content

Commit

Permalink
Re-generate the README file
Browse files Browse the repository at this point in the history
  • Loading branch information
coatless committed Jan 11, 2024
1 parent 7a19224 commit d31378a
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 23 deletions.
67 changes: 55 additions & 12 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
output:
github_document:
github_document
#fig_width: 7
#fig_height: 5 # default is 5
toc: true
toc_depth: 2
---

<!-- README.md is generated from README.Rmd. Please edit that file -->
Expand Down Expand Up @@ -35,24 +33,69 @@ You can install the development version of drawr from [GitHub](https://github.co
devtools::install_github("coatless-rpkg/drawr")
```

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

- `draw_*()`: base R graphics
- `gdraw_*()`: `ggplot2`

## Example

This is a basic example which shows you how to solve a common problem:
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 layed out with their indices?

```{r}
#| label: example
#| results: "output"
#| label: base-example
#| results: 'markup'
# Load the library
library(drawr)
# Randomly filled matrix
mat_3x5 = matrix(round(rnorm(15, 0, 4), 2), ncol = 5)
# Graphic of matrix data structure using base R graphics
draw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
draw_matrix(mat_3x5)
# Disable showing the cell indices
draw_matrix(mat_3x5, show_cell_indices = FALSE)
# Disable showing any indices
draw_matrix(
mat_3x5,
show_row_indices = TRUE, show_column_indices = TRUE,
show_cell_indices = FALSE)
# Highlight cells over a specific value
draw_matrix(mat_3x5, highlight_cells = mat_3x5 > 4)
```

We can achieve similar results with the `ggplot2` function.

# Graphic of matrix data structure using ggplot2
gdraw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
```{r}
#| label: ggplot2-example
#| results: 'markup'
# Graphic of matrix data structure using base R graphics
gdraw_matrix(mat_3x5)
# Disable showing the cell indices
gdraw_matrix(mat_3x5, show_cell_indices = FALSE)
# Show row and column indices
gdraw_matrix(
mat_3x5,
show_row_indices = TRUE, show_column_indices = TRUE,
show_cell_indices = FALSE)
# Highlight cells over a specific value
gdraw_matrix(mat_3x5, highlight_cells = mat_3x5 > 4)
```



96 changes: 85 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

- [drawr](#drawr)
- [Installation](#installation)
- [Example](#example)

<!-- README.md is generated from README.Rmd. Please edit that file -->

# drawr
Expand All @@ -24,22 +20,100 @@ You can install the development version of drawr from
devtools::install_github("coatless-rpkg/drawr")
```

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

- `draw_*()`: base R graphics
- `gdraw_*()`: `ggplot2`

## Example

This is a basic example which shows you how to solve a common problem:
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
#> [,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 layed out with their indices?

``` r
# Load the library
library(drawr)

# Randomly filled matrix
mat_3x5 = matrix(round(rnorm(15, 0, 4), 2), ncol = 5)
# Graphic of matrix data structure using base R graphics
draw_matrix(mat_3x5)
```

<img src="man/figures/README-base-example-1.png" width="100%" />

``` r
# Disable showing the cell indices
draw_matrix(mat_3x5, show_cell_indices = FALSE)
```

<img src="man/figures/README-base-example-2.png" width="100%" />

``` r
# Disable showing any indices
draw_matrix(
mat_3x5,
show_row_indices = TRUE, show_column_indices = TRUE,
show_cell_indices = FALSE)
```

<img src="man/figures/README-base-example-3.png" width="100%" />

``` r
# Highlight cells over a specific value
draw_matrix(mat_3x5, highlight_cells = mat_3x5 > 4)
```

<img src="man/figures/README-base-example-4.png" width="100%" />

We can achieve similar results with the `ggplot2` function.

``` r
# Graphic of matrix data structure using base R graphics
draw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
gdraw_matrix(mat_3x5)
```

<img src="man/figures/README-ggplot2-example-1.png" width="100%" />

# Graphic of matrix data structure using ggplot2
gdraw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
``` r
# Disable showing the cell indices
gdraw_matrix(mat_3x5, show_cell_indices = FALSE)
```

<img src="man/figures/README-ggplot2-example-2.png" width="100%" />

``` r
# Show row and column indices
gdraw_matrix(
mat_3x5,
show_row_indices = TRUE, show_column_indices = TRUE,
show_cell_indices = FALSE)
```

<img src="man/figures/README-ggplot2-example-3.png" width="100%" />

``` r
# Highlight cells over a specific value
gdraw_matrix(mat_3x5, highlight_cells = mat_3x5 > 4)
```

<img src="man/figures/README-example-1.png" width="100%" /><img src="man/figures/README-example-2.png" width="100%" />
<img src="man/figures/README-ggplot2-example-4.png" width="100%" />
Binary file added man/figures/README-base-example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-base-example-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-base-example-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-base-example-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed man/figures/README-example-1.png
Binary file not shown.
Binary file removed man/figures/README-example-2.png
Binary file not shown.
Binary file added man/figures/README-ggplot2-example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-ggplot2-example-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-ggplot2-example-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-ggplot2-example-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d31378a

Please sign in to comment.