Skip to content

Commit

Permalink
Rename:
Browse files Browse the repository at this point in the history
visualize_matrix_data_ggplot -> draw_matrix

visualize_matrix_data_ggplot -> gdraw_matrix
  • Loading branch information
coatless committed Jan 11, 2024
1 parent b023ec2 commit acf206e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 30 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(visualize_matrix_data)
export(visualize_matrix_data_ggplot)
export(draw_matrix)
export(gdraw_matrix)
importFrom(graphics,rect)
importFrom(graphics,text)
32 changes: 19 additions & 13 deletions R/matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@
#'
#' # Visualize a 3x3
#' mat_3x3 = matrix(c(10, 200, -30, 40, 500, 30, 90, -55, 10), ncol = 3)
#' visualize_matrix_data(mat_3x3)
#' draw_matrix(mat_3x3)
#'
#' # Disable the indices
#' visualize_matrix_data(mat_3x3, show_indices = FALSE)
#' draw_matrix(mat_3x3, show_indices = FALSE)
#'
#' # Highlight a row
#' mat_2x2 = matrix(c(1, 2, 3, 4), nrow = 2)
#' mat_2x2_mask = matrix(c(TRUE, TRUE, FALSE, FALSE), nrow = 2)
#' visualize_matrix_data(mat_2x2, highlight_cells = mat_2x2_mask)
#' draw_matrix(mat_2x2, highlight_cells = mat_2x2_mask)
#'
#' # Highlight values above 5
#' mat_3x5 = matrix(rnorm(15, 5, 2), ncol = 5)
#' visualize_matrix_data(mat_3x5, highlight_cells = mat_3x5 > 2)
visualize_matrix_data <- function(data, show_indices = TRUE,
highlight_cells = matrix(FALSE, nrow(data), ncol(data)),
highlight_color = "lemonchiffon") {
#' draw_matrix(mat_3x5, highlight_cells = mat_3x5 > 2)
draw_matrix <- function(
data,
show_indices = TRUE,
highlight_cells = matrix(FALSE, nrow(data), ncol(data)),
highlight_color = "lemonchiffon"
) {

if (!is.matrix(data)) {
message("Please double check the data supplied is of a matrix type.")
stop("Please double check the data supplied is of a matrix type.")
}

nrow <- nrow(data)
Expand Down Expand Up @@ -123,16 +126,19 @@ visualize_matrix_data <- function(data, show_indices = TRUE,
#' # Highlight values above 5
#' mat_3x5 = matrix(rnorm(15, 5, 2), ncol = 5)
#' visualize_matrix_data(mat_3x5, highlight_cells = mat_3x5 > 2)
visualize_matrix_data_ggplot <- function(data, show_indices = TRUE,
highlight_cells = matrix(FALSE, nrow(data), ncol(data)),
highlight_color = "lemonchiffon") {
gdraw_matrix <- function(
data,
show_indices = TRUE,
highlight_cells = matrix(FALSE, nrow(data), ncol(data)),
highlight_color = "lemonchiffon"
) {

if(!requireNamespace("ggplot2", quietly = TRUE)) {
message("Please make sure `ggplot2` is installed to use this function.")
stop("Please make sure `ggplot2` is installed to use this function.")
}

if (!is.matrix(data)) {
message("Please double-check the data supplied is of a matrix type.")
stop("Please double-check the data supplied is of a matrix type.")
}

nrow <- nrow(data)
Expand Down
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ knitr::opts_chunk$set(
[![R-CMD-check](https://github.com/coatless-rpkg/drawr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/coatless-rpkg/drawr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of drawr is to draw different R data structures on graphics
The goal of `drawr` is to draw different _R_ data structures on graphs.

## Installation

Expand All @@ -49,10 +49,10 @@ library(drawr)
mat_3x5 = matrix(round(rnorm(15, 0, 4), 2), ncol = 5)
# Graphic of matrix data structure using base R graphics
visualize_matrix_data(mat_3x5, highlight_cells = mat_3x5 > 0)
draw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
# Graphic of matrix data structure using ggplot2
visualize_matrix_data_ggplot(mat_3x5, highlight_cells = mat_3x5 > 0)
gdraw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
```


6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![R-CMD-check](https://github.com/coatless-rpkg/drawr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/coatless-rpkg/drawr/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->

The goal of drawr is to draw different R data structures on graphics
The goal of `drawr` is to draw different *R* data structures on graphs.

## Installation

Expand All @@ -36,10 +36,10 @@ library(drawr)
mat_3x5 = matrix(round(rnorm(15, 0, 4), 2), ncol = 5)

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

# Graphic of matrix data structure using ggplot2
visualize_matrix_data_ggplot(mat_3x5, highlight_cells = mat_3x5 > 0)
gdraw_matrix(mat_3x5, highlight_cells = mat_3x5 > 0)
```

<img src="man/figures/README-example-1.png" width="100%" /><img src="man/figures/README-example-2.png" width="100%" />
18 changes: 9 additions & 9 deletions man/draw-matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified man/figures/README-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 modified man/figures/README-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.

0 comments on commit acf206e

Please sign in to comment.