Skip to contents

Facet app inputs

Usage

pull_facet_cols(df)

Arguments

df

a data.frame or tibble

Value

a named character vector of factor or character column names with < 5 unique levels

Variables to use for facets

This function is designed to quickly determine which variables have an appropriate number of categorical levels for using ggplot2::facet_wrap() or ggplot2::facet_grid()

Examples

require(dplyr)
require(NHANES)
#> Loading required package: NHANES
#> Warning: there is no package called ‘NHANES’
pull_facet_cols(df = dplyr::starwars)
#>   sex 
#> "sex" 
pull_facet_cols(df = NHANES::NHANES)
#> Error in purrr::map(.x = class, .f = col_class, df = df):  In index: 1.
#> Caused by error in `loadNamespace()`:
#> ! there is no package called ‘NHANES’

str(dplyr::select(
  dplyr::starwars,
  dplyr::all_of(pull_facet_cols(df = dplyr::starwars))
))
#> tibble [87 × 1] (S3: tbl_df/tbl/data.frame)
#>  $ sex: chr [1:87] "male" "none" "none" "male" ...
str(dplyr::select(
  NHANES::NHANES,
  dplyr::all_of(pull_facet_cols(df = NHANES::NHANES))
))
#> Error in loadNamespace(x): there is no package called ‘NHANES’