alter_at: Alter aesthetics / structures at certain areas of a grob...

Description Usage Arguments Value Examples

View source: R/alter.R

Description

Flexibly alter the aesthetic / structure of a grob matrix object at specific points of the data.frame/matrix.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
alter_at(
  grob_object,
  .f = NULL,
  ...,
  columns = NULL,
  rows = NULL,
  data = NULL,
  structure = NULL,
  aesthetic = NULL,
  group = NULL
)

Arguments

grob_object

The R6 grob object class initialized by grob_matrix.

.f

A quosure style lambda ~ fun(.), which the user wants to apply to the specific subset of cells.

...

Logical predicates defined in terms of the variables in the initial data frame / matrix, or if the user provides a new data.frame to evaluate via data. Multiple conditions are combined with &. Only rows where the condition evaluates to TRUE are evaluated.

If no logical predicates provided, then the entire columns will be altered.

columns

A character vector of column names, or numeric column indices, of the initial data.frame/matrix, or data if it is provided, the user wishes to alter.

rows

A numeric vector of row indices, of the initial data.frame/matrix, or data if it is provided, the user wishes to alter.

Ignored if the user is altering a structure and not an aesthetic.

data

A separate data.frame/matrix of the same dimensions as the initial data.frame/matrix which the .f function and any filters will be applied to.

Must match the dimensions of the subset of the initial data.frame/matrix the user is attempting to alter.

Ignored if the user is altering a structure and not an aesthetic.

structure

Which structure the user wants to make alterations to. If left NULL and aesthetic is left NULL, the function will look for the most previous altered structure, either via add_structure, or a previous application of alter_at.

View the documentation of add_structure for a list of accepted structures

aesthetic

Which aesthetic the user wants to make alterations to. If left NULL and structure is left NULL, the function will look for the most previous altered aesthetic, either via add_aesthetic, or a previous application of alter_at.

View the documentation of add_aesthetic for a list of accepted aesthetics.

group

Which group of elements the user wants to make alterations to. If left NULL, the function will look for the most previous altered group, either via add_aesthetic, or a previous application of alter_at.

Value

The R6 grob matrix object class with its aesthetic / structure properties altered.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
df = data.frame(var1 = c(5, 14, 6, 10), var2 = c(3, 30, 17, 7))
df %>%
  grob_matrix() %>%
  add_aesthetic(aesthetic = 'text_color', group = 'cells', value = 'red') %>%
  alter_at(
    .f = ~ 'blue',
    abs(var2 - var1) > 1
    ) %>%
  view_grob()

test_function = function(x) ifelse(x > 15, 2, 1)

df %>%
  grob_matrix() %>%
  alter_at(
    .f = ~ test_function(.),
    aesthetic = 'font_face',
    group = 'cells'
    ) %>%
  view_grob()
  
df %>%
  grob_matrix() %>%
  add_structure("column_widths_p", 1) %>%
  alter_at(
    .f = ~ 2,
    columns = 1
    ) %>%
  view_grob()
  

grobblR documentation built on Sept. 15, 2021, 1:07 a.m.