if (FALSE) {
## Load package:
library("diversityForest")
## Plot "density" and "boxplot" plots (default: plot_type = "both") for the
## first three variables in the "hars" dataset:
data(hars)
plotMcl(data = hars, yvarname = "Activity", varnames = c("tBodyAcc.mean...X",
"tBodyAcc.mean...Y",
"tBodyAcc.mean...Z"))
## Plot only the "density" plots for these variables:
plotMcl(data = hars, yvarname = "Activity",
varnames = c("tBodyAcc.mean...X", "tBodyAcc.mean...Y",
"tBodyAcc.mean...Z"), plot_type = "density")
## Plot the "density" plots for these variables, but without titles of the
## plots:
plotMcl(data = hars, yvarname = "Activity", varnames =
c("tBodyAcc.mean...X", "tBodyAcc.mean...Y", "tBodyAcc.mean...Z"),
plot_type = "density", addtitles = FALSE)
## Make density plots for these variables, but only save them in a list "ps"
## without plotting them ("plotit = FALSE"):
ps <- plotMcl(data = hars, yvarname = "Activity", varnames =
c("tBodyAcc.mean...X", "tBodyAcc.mean...Y",
"tBodyAcc.mean...Z"), plot_type = "density",
addtitles = FALSE, plotit = FALSE)
## The plots can be manipulated later by using ggplot2 functionalities:
library("ggplot2")
p1 <- ps[[1]] + ggtitle("First variable in the dataset") +
labs(x="Variable values", y="my scaled density")
p2 <- ps[[3]] + ggtitle("Third variable in the dataset") +
labs(x="Variable values", y="my scaled density")
## Combine both of the above plots:
library("ggpubr")
p <- ggarrange(p1, p2, ncol = 2)
p
## # Save as PDF:
## ggsave(file="mypathtofolder/FigureXY1.pdf", width=14, height=6)
}
Run the code above in your browser using DataLab