plot_assoc: Plot variables.

Description Usage Arguments Value Author(s) Examples

View source: R/plot_assoc.R

Description

Plots one or a pair of variables (non) interactively using ggplot2 and highcharter packages.

Usage

1

Arguments

data

A dataframe. It is strongly recommended that the dataframe has no missing data and is preprocessed.

vars

A vector of length one or two including the name (or index) of a (row) column(s) of data.

levels

An integer value indicating the maximum number of levels of a categorical variable. To be used to distinguish the categorical variable. Defaults to NULL because it is supposed that data has been preprocessed using data_preproc and the categorical variables are specified.

interactive

Logical indicating if the output should be interactive. Defaults to FALSE.

Value

There may be 5 scenarios for vars:

One categorical variable

Plots the barplot of the variable.

One continuous variable

Plots the density (histogram) plot of the variable.

A categorical and a continuous variable

Plots a Boxplot (or violin plot in non-interactive mode) of the continuous variable for different levels of the categorical variable.

Two continuous variables

Plots a scatter plot of two variables.

Two categorical variables

Plots a relative histogram (or heatmap in non-interactive mode) showing distribution of one variable for each level of the other.

(Plots interactively If interactive = TRUE).

Author(s)

Elyas Heidari, Vahid Balazadeh

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Preprocess the data
data("NHANES")
data <- data_preproc(NHANES, levels = 15)

## Plot (non)interactive for:
## One categorical variable
pt1 <- plot_assoc(data, vars = "PAD600")
pt2 <- plot_assoc(data, vars = "SMD410", interactive = TRUE)

## One continuous variable
pt3 <- plot_assoc(data, vars = "LBXTC")
pt4 <- plot_assoc(data, vars = "BMXBMI", interactive = TRUE)

## One continuous and one categorical variable
pt5 <- plot_assoc(data, vars = c("LBXTC", "RIAGENDR"))
pt6 <- plot_assoc(data, vars = c("BMXBMI", "PAD600"), interactive = TRUE)
##  Two continuous variables
pt7 <- plot_assoc(data, vars = c("LBXTC", "BMXBMI"))
pt8 <- plot_assoc(data, vars = c("LBXVIE", "LBXVIC"), interactive = TRUE)

## Two categorical variables
pt9 <- plot_assoc(data, vars = c("SMD410", "PAD600"))
pt10 <- plot_assoc(data, vars = c("PAD600", "SMD410"), interactive = TRUE)

## With raw data
pt11 <- plot_assoc(NHANES, vars = "RIDAGEYR", levels = 15)

bAIo-lab/Questools documentation built on Nov. 9, 2019, 3:59 a.m.