Learn R Programming

dlookr (version 0.3.9)

plot_normality: Plot distribution information of numerical data

Description

The plot_normality() visualize distribution information for normality test of the numerical data.

Usage

plot_normality(.data, ...)

# S3 method for data.frame plot_normality(.data, ...)

Arguments

.data

a data.frame or a tbl_df.

...

one or more unquoted expressions separated by commas. You can treat variable names like they are positions. Positive values select variables; negative values to drop variables. If the first expression is negative, plot_normality() will automatically start with all variables. These arguments are automatically quoted and evaluated in a context where column names represent column positions. They support unquoting and splicing.

See vignette("EDA") for an introduction to these concepts.

Distribution information

The plot derived from the numerical data vizualization is as follows.

  • histogram by original data

  • q-q plot by original data

  • histogram by log transfer data

  • histogram by square root transfer data

Details

The scope of the visualization is the provide a distribution information. Since the plot is drawn for each variable, if you specify more than one variable in the ... argument, the specified number of plots are drawn.

See Also

plot_normality.tbl_dbi, plot_outlier.data.frame.

Examples

Run this code
# NOT RUN {
# Generate data for the example
carseats <- ISLR::Carseats
carseats[sample(seq(NROW(carseats)), 20), "Income"] <- NA
carseats[sample(seq(NROW(carseats)), 5), "Urban"] <- NA

# Visualization of all numerical variables
plot_normality(carseats)

# Select the variable to plot
plot_normality(carseats, Income, Price)
plot_normality(carseats, -Income, -Price)
plot_normality(carseats, 1)

# Using dtplyr::grouped_dt
library(dplyr)

gdata <- group_by(carseats, ShelveLoc, US)
plot_normality(carseats)
plot_normality(carseats, "Sales")

# Using pipes ---------------------------------
# Visualization of all numerical variables
carseats %>%
 plot_normality()

# Positive values select variables
carseats %>%
plot_normality(Income, Price)

# Positions values select variables
carseats %>%
 plot_normality(1)

# Using pipes & dplyr -------------------------
# Plot 'Sales' variable by 'ShelveLoc' and 'US'
carseats %>%
 group_by(ShelveLoc, US) %>%
 plot_normality(Sales)

# extract only those with 'ShelveLoc' variable level is "Good",
# and plot 'Income' by 'US'
carseats %>%
 filter(ShelveLoc == "Good") %>%
 group_by(US) %>%
 plot_normality(Income)
# }

Run the code above in your browser using DataLab