Description Usage Arguments Value Author(s) Examples
Plots one or a pair of variables (non) interactively using ggplot2 and highcharter packages.
1 | plot_assoc(data, vars, levels = NULL, interactive = FALSE)
|
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 |
interactive |
Logical indicating if the output should be interactive. Defaults to FALSE. |
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).
Elyas Heidari, Vahid Balazadeh
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.