Learn R Programming

cspp (version 0.3.3)

corr_plot: Create correlation plots of CSPP data

Description

corr_plot takes CSPP data from get_cspp_data and returns either a correlation matrix or correlation plot.

Usage

corr_plot(
  data = NULL,
  vars = NULL,
  summarize = TRUE,
  labels = TRUE,
  label_size = 3,
  colors = c("#6D9EC1", "#FFFFFF", "#E46726"),
  cor_matrix = FALSE
)

Value

ggplot2 object or correlation matrix

Arguments

data

A dataframe. If data is generated by get_cspp_data function, the function can automatically parse the dataframe. Otherwise, this function will attempt to make a correlation plot or matrix from all numeric variables within the passed dataframe.

vars

Default is NULL. If left NULL, uses all variables within the passed dataframe. Otherwise, must be a character vector. The dataframe is subset based on variables listed.

summarize

Default is TRUE. If TRUE, and if the variable st is present, the function will create state specific averages for each variable in the dataframe. If FALSE, the function will generate the correlation matrix and plot for all values in the dataset.

labels

Default is TRUE. If TRUE, the correlation plot will include labels for the correlation value. If FALSE, no labels will be present.

label_size

Default is 3. Controls the size of the font for labels.

colors

Specify the colors to be used in the correlation plot. Must include three values in a character vector format. The default values are `c("#6D9EC1", "#FFFFFF", "#E46726")`.

cor_matrix

Default is FALSE. If set to TRUE, instead of returning a ggplot object that is a correlation plot, returns a correlation matrix. This is particularly useful if you want to customize the output with ggcorrplot.

Details

This function is a wrapper that passes a dataframe to the ggcorrplot::ggcorrplot function which generates correlation heat plots.

See Also

ggcorrplot

Examples

Run this code

corr_plot(data = get_cspp_data(), vars = c("pollib_median",
 "innovatescore_boehmkeskinner", "citi6013", "ranney4_control", "h_diffs"),
 cor_matrix = FALSE)

Run the code above in your browser using DataLab