regression_vis: Correlation and cross product visualization

View source: R/regression_vis.R

regression_visR Documentation

Correlation and cross product visualization

Description

Correlation and cross product visualization

Usage

regression_vis(
  df,
  x_var = names(df)[1],
  y_var = names(df)[2],
  plot_x_mean = TRUE,
  plot_y_mean = TRUE,
  plot_regression = FALSE,
  regression_line_color = "grey30",
  plot_x_deviations = NULL,
  plot_y_deviations = NULL,
  x_deviation_color = "darkblue",
  y_deviation_color = "darkblue",
  deviation_size = 1.5,
  plot_positive_cross_products = FALSE,
  plot_negative_cross_products = FALSE,
  plot_cross_products = NULL,
  positive_cross_product_fill = "lightblue",
  negative_cross_product_fill = "darkred",
  positive_cross_product_color = cross_product_color,
  negative_cross_product_color = cross_product_color,
  cross_product_color = "grey30",
  cross_product_fill = "#F5C710",
  cross_product_alpha = 0.1,
  plot_residuals = NULL,
  plot_residuals_squared = NULL,
  residuals_squared_color = "grey30",
  residuals_squared_fill = "green",
  residuals_squared_alpha = 0.1,
  residual_color = "darkred",
  residual_size = 1.5
)

Arguments

df

data.frame with the data to plot.

x_var

the name of the variable for the x-axis.

y_var

the name of the variable fro teh y-axis.

plot_x_mean

plot a line for the mean of x.

plot_y_mean

plot a line for the mean of y.

plot_regression

whether to plot the linear regression line.

regression_line_color

color for the regression line.

plot_x_deviations

either a logical or numerical vector for the rows in df to plot the x deviations.

plot_y_deviations

either a logical or numerical vector for the rows in df to plot the y deviations.

x_deviation_color

the color of the line for x deviations.

y_deviation_color

the color of the line for y deviations.

deviation_size

of the line when plotting deviations.

plot_positive_cross_products

plot all the cross products in the 1st and 3rd quadrants.

plot_negative_cross_products

plot all the cross products in the 2nd and 4th quandrants.

plot_cross_products

either a logicial or numerical vector for the rows in df to plot the cross products.

positive_cross_product_fill

the fill for the positive cross products.

negative_cross_product_fill

the fill for the negative cross products.

positive_cross_product_color

the color of the square for positive cross products.

negative_cross_product_color

the color of the square for negative cross products.

cross_product_color

the color of the square for cross products.

cross_product_fill

the fill for the cross products plotted by plot_cross_products.

cross_product_alpha

the alpha level (transparency) for the cross product fill.

plot_residuals

whether to plot the residuals.

plot_residuals_squared

whether to plot the squared residuals.

residuals_squared_color

color for the residuals.

residuals_squared_fill

fill color for the squared residuals.

residuals_squared_alpha

alpha (transparency) level for the squared residuals.

residual_color

color for the residuals.

residual_size

size of the residuals.

Value

a ggplot2 expression.

Examples

df <- mtcars[,c('wt', 'mpg')]
cross_products <- abs(df[,1] * df[,2])
cross_products == max(cross_products) # Find the largest cross product

# Scatter plot with arrows showing the largest cross product
regression_vis(df,
				plot_x_mean = TRUE,
				plot_y_mean = TRUE,
				plot_positive_cross_products = FALSE,
				plot_negative_cross_products = FALSE,
				plot_x_deviations = cross_products == max(cross_products),
				plot_y_deviations = cross_products == max(cross_products))

# Scatter plot with the largest cross product as a rectangl
regression_vis(df,
				plot_x_mean = TRUE,
				plot_y_mean = TRUE,
				plot_positive_cross_products = FALSE,
				plot_negative_cross_products = FALSE,
				plot_cross_products = cross_products == max(cross_products),
				cross_product_alpha = 0.5)

# Scatter plot with all the cross products.
regression_vis(df,
				plot_x_mean = TRUE,
				plot_y_mean = TRUE,
				plot_positive_cross_products = TRUE,
				plot_negative_cross_products = TRUE)


jbryer/VisualStats documentation built on Feb. 27, 2025, 6:19 p.m.