as.data.frame.bm_matrix: Convert to data frame with pixel (x,y) coordinates

as.data.frame.bm_bitmapR Documentation

Convert to data frame with pixel (x,y) coordinates

Description

as.matrix.bm_matrix() casts bm_bitmap() objects to a (normal) integer matrix and bm_pixmap() objects to a (normal) character matrix (of color strings).

Usage

## S3 method for class 'bm_bitmap'
as.data.frame(x, ..., filtrate = FALSE)

## S3 method for class 'bm_pixmap'
as.data.frame(x, ..., filtrate = FALSE)

Arguments

x

Either a bm_bitmap() or bm_pixmap() object.

...

Currently ignored.

filtrate

If FALSE (default) get coordinates for all values. If a single value only return the coordinates for pixels that equal that value.

Value

A data frame with "x", "y", and "value" columns.

Examples

font_file <- system.file("fonts/fixed/4x6.yaff.gz", package = "bittermelon")
font <- read_yaff(font_file)
bm <- as_bm_bitmap("RSTATS", font = font)
df <- as.data.frame(bm, filtrate = 1L)
if (require("grid")) {
  grid.newpage()
  grid.rect(df$x * 0.6, df$y * 0.6, width = 0.5, height = 0.5,
            gp = gpar(fill = 'black'), default.units = 'cm')
}

corn <- farming_crops_16x16()$corn$portrait
df <- as.data.frame(corn)
if (require("grid")) {
  grid.newpage()
  grid.circle(df$x * 0.6, df$y * 0.6, r = 0.25,
              gp = gpar(fill = df$value), default.units = 'cm')
}

trevorld/bittermelon documentation built on Dec. 24, 2024, 10:33 p.m.