# NOT RUN {
# Visualization of all numerical variables
heartfailure2 <- heartfailure[, c("creatinine", "platelets", "sodium", "sex", "smoking")]
plot_normality(heartfailure2)
# Select the variable to plot
plot_normality(heartfailure2, platelets, sodium)
plot_normality(heartfailure2, -platelets, -sodium, col = "gray")
plot_normality(heartfailure2, 1)
# Change the method of transformation
plot_normality(heartfailure2, platelets, right = "1/x")
if (requireNamespace("forecast", quietly = TRUE)) {
plot_normality(heartfailure2, platelets, left = "Box-Cox", right = "Yeo-Johnson")
} else {
cat("If you want to use this feature, you need to install the rpart package.\n")
}
# Not allow typographic elements
plot_normality(heartfailure2, platelets, typographic = FALSE)
# Using dplyr::grouped_df
library(dplyr)
gdata <- group_by(heartfailure2, sex, smoking)
plot_normality(gdata)
plot_normality(gdata, "creatinine")
# Using pipes ---------------------------------
# Visualization of all numerical variables
heartfailure2 %>%
plot_normality()
# Positive values select variables
heartfailure2 %>%
plot_normality(platelets, sodium)
# Positions values select variables
# heartfailure2 %>%
# plot_normality(1)
# Using pipes & dplyr -------------------------
# Plot 'creatinine' variable by 'sex' and 'smoking'
heartfailure2 %>%
group_by(sex, smoking) %>%
plot_normality(creatinine)
# extract only those with 'sex' variable level is "Male",
# and plot 'platelets' by 'smoking'
if (requireNamespace("forecast", quietly = TRUE)) {
heartfailure2 %>%
filter(sex == "Male") %>%
group_by(smoking) %>%
plot_normality(platelets, right = "Box-Cox")
} else {
cat("If you want to use this feature, you need to install the rpart package.\n")
}
# }
Run the code above in your browser using DataLab