poly_plot: Plot a polynomial matrix

View source: R/polypoly-package.R

poly_plotR Documentation

Plot a polynomial matrix

Description

Plot a polynomial matrix

Usage

poly_plot(x, by_observation = TRUE, x_col = 1)

poly_plot_data(x, by_observation = TRUE, x_col = 1)

Arguments

x

a matrix created by stats::poly()

by_observation

whether the x axis should be mapped to the observation/row number (TRUE, the default) or to the degree-1 terms of the matrix (FALSE)

x_col

integer indicating which column to plot as the x-axis when by_observation is FALSE. Default is 1 (assumes the first column is the linear polynomial term).

Value

a ggplot2::ggplot() plot of the degree terms from the matrix. For poly_plot_data(), the dataframe used to create the plot is returned instead.

Examples

# Defaults to plotting using the row number as x-axis
m <- poly(1:100, degree = 3)
poly_plot(m)

# Not good because observations were not sorted
m2 <- poly(rnorm(100), degree = 3)
poly_plot(m2)

# Instead set by_observation to FALSE to plot along the degree 1 values
poly_plot(m2, by_observation = FALSE)

# Get a dataframe instead of plot
poly_plot_data(m2, by_observation = FALSE)

polypoly documentation built on Oct. 20, 2022, 9:05 a.m.