Skip to contents

Visualize all columns in a data frame with gg1d's vertically aligned plots and automatic plot selection based on variable type. Plots are fully interactive, and custom tooltips can be added.

Usage

gg1d(
  data,
  col_id = NULL,
  col_sort = NULL,
  order_matches_sort = TRUE,
  maxlevels = 6,
  verbose = 2,
  drop_unused_id_levels = FALSE,
  interactive = TRUE,
  return = c("plot", "column_info", "data"),
  palettes = NULL,
  sort_type = c("frequency", "alphabetical"),
  desc = TRUE,
  limit_plots = TRUE,
  max_plottable_cols = 15,
  cols_to_plot = NULL,
  tooltip_column_suffix = "_tooltip",
  ignore_column_regex = "_ignore$",
  options = gg1d_options(show_legend = !interactive)
)

Arguments

data

data.frame to autoplot (data.frame)

col_id

name of column to use as an identifier. If null, artificial IDs will be created based on row-number.

col_sort

name of columns to sort on. To do a hierarchical sort, supply a vector of column names in the order they should be sorted (character).

order_matches_sort

should the column plots be stacked top-to-bottom in the order they appear in .arg col_sort (flag)

maxlevels

for categorical variables, what is the maximum number of distinct values to allow (too many will make it hard to find a palette that suits). (number)

verbose

Numeric value indicating the verbosity level:

  • 2: Highly verbose, all messages.

  • 1: Key messages only.

  • 0: Silent, no messages.

drop_unused_id_levels

if col_id is a factor with unused levels, should these be dropped or included in visualisation

interactive

produce interactive ggiraph visualiastion (flag)

return

a string describing what this function should return. Options include:

  • plot: Return the gg1d visualisation (default)

  • colum_info: Return a data.frame describing the columns the dataset.

  • data: Return the processed dataset used for plotting.

palettes

A list of named vectors. List names correspond to data column names (categorical only). Vector names to levels of columns. Vector values are colours, the vector names are used to map values in data to a colour.

sort_type

controls how categorical variables are sorted. Numerical variables are always sorted in numerical order irrespective of the value given here. Options are alphabetical or frequency

desc

sort in descending order (flag)

limit_plots

throw an error when there are > max_plottable_cols in dataset (flag)

max_plottable_cols

maximum number of columns that can be plotted (default: 15) (number)

cols_to_plot

names of columns in data that should be plotted. By default plots all valid columns (character)

tooltip_column_suffix

the suffix added to a column name that indicates column should be used as a tooltip (string)

ignore_column_regex

a regex string that, if matches a column name, will cause that column to be exclude from plotting (string) (default: "_ignore$")

options

a list of additional visual parameters created by calling gg1d_options(). See gg1d_options for details.

Value

ggiraph interactive visualisation

Examples

path_gg1d <- system.file("example.csv", package = "gg1d")
df <- read.csv(path_gg1d, header = TRUE, na.strings = "")

# Create Basic Plot
gg1d(df, col_id = "ID", col_sort = "Glasses")
#> 
#> ── Running gg1d ────────────────────────────────────────────────────────────────
#> 
#> ── Sorting 
#>  Sorting X axis by: Glasses
#>  Order type: frequency
#>  Sort order: descending
#> ! Categorical columns must have <= 6 unique values to be visualised. Columns with too many unique values: Date (19)
#> 
#> ── Generating Plot 
#>  Found 7 plottable columns in data
#>  Plotting column Glasses
#>  Plotting column Age
#>  Plotting column Gender
#>  Plotting column EyeColour
#>  Plotting column Height
#>  Plotting column HairColour
#>  Plotting column WearingHat
#> ! Skipping column WearingHat_tooltip
#> ! Skipping column Date
#>  Stacking plots vertically
#>  Making plot interactive since `interactive = TRUE`
# Configure plot gg1d_options() gg1d( lazy_birdwatcher, col_sort = "Magpies", palettes = list( Birdwatcher = c(Robert = "#E69F00", Catherine = "#999999"), Day = c(Weekday = "#999999", Weekend = "#009E73") ), options = gg1d_options( show_legend = TRUE, fontsize_barplot_y_numbers = 12, legend_text_size = 16, legend_key_size = 1, legend_nrow = 1, ) ) #> #> ── Running gg1d ──────────────────────────────────────────────────────────────── #> #> ── Sorting #> Sorting X axis by: Magpies #> Order type: frequency #> Sort order: descending #> #> ── Generating Plot #> Found 3 plottable columns in data #> Plotting column Magpies #> Plotting column Day #> Plotting column Birdwatcher #> Stacking plots vertically #> Making plot interactive since `interactive = TRUE`