plot_pairs: plot_pairs

View source: R/plot_pairs.R

plot_pairsR Documentation

plot_pairs

Description

Function produces a ggplot2 based scatter plot of all pairs of a dataframe's variables.

In creating the 'var_name_scaling' list, if we are looking at some regression model, then suggest listing the response variable last.

Usage

plot_pairs(
  df,
  var_name_scaling,
  title = NULL,
  title_sz = 14,
  axis_text_sz = 6,
  rot_y_tic_label = FALSE,
  plot_dim = 12
)

Arguments

df

The required data frame from which the scatter plots' values are derived and laid out in a matrix like fashion.

var_name_scaling

A required named list where the name is the variable name from 'df' and the value is a vector defining the corresponding major axis scaling breaks. If the value is NULL, then ggplot2 figures out the variable's scaling. The vector can be numeric/dates or anything acceptable in scaling a ggplot2 axis.

title

A string that sets the overall title.

title_sz

A numeric that sets the title's font size. Default is 14.

axis_text_sz

A numeric that sets the font size along the axis'. Default is 6.

rot_y_tic_label

A logical which if TRUE rotates the y tic labels 90 degrees for enhanced readability.

plot_dim

A numeric that sets the overall width/height of the plot in centimeters.

Value

a ggplot2 plot object

Examples

library(ggplot2)
library(ggplotify)
library(gtable)
library(data.table)
library(RplotterPkg)
library(RregressPkg)

# Advertising media
var_name_scaling_lst <- list(
TV = NULL,
radio = NULL,
newspaper = NULL,
sales = NULL
)

a_plot <- RregressPkg::plot_pairs(
  df = RregressPkg::advertising,
  var_name_scaling = var_name_scaling_lst,
  title = "Advertising Predictors of Sales",
  rot_y_tic_label = TRUE
)

# Timber volume
data(trees)

var_name_scaling_lst <- list(
Girth = seq(5, 25, 5),
Height = seq(60, 90, 5),
Volume = NULL
)
a_plot <- RregressPkg::plot_pairs(
  df = trees,
  var_name_scaling = var_name_scaling_lst,
  title = "Cherry Trees"
)


deandevl/RregressPkg documentation built on Feb. 5, 2025, 12:11 p.m.