if (FALSE) {
## Load package:
library("diversityForest")
## Load the "ctg" data set:
data(ctg)
## Set seed to make results reproducible (this is necessary because
## the rug plot produced by 'plotVar' does not show all observations, but
## only a random subset of 1000 observations):
set.seed(1234)
## Using a "density" plot and a "boxplot", visualise the (estimated)
## distributions of the variable "Mean" for each of the categories of the
# variable "Tendency":
plotVar(x = ctg$Mean, y = ctg$Tendency)
## Re-create this plot with labels:
plotVar(x = ctg$Mean, y = ctg$Tendency, x_label = "Mean of the histogram ('Mean')",
y_label = "Histogram tendency ('Tendency')",
plot_title = "Relationship between 'Mean' and 'Tendency'")
## Re-create this plot, but only show the "density" plot:
plotVar(x = ctg$Mean, y = ctg$Tendency, plot_type = "density",
x_label = "Mean of the histogram ('Mean')",
y_label = "Histogram tendency ('Tendency')",
plot_title = "Relationship between 'Mean' and 'Tendency'")
## Use ggplot2 and RColorBrewer functionalities to change the line colors and
## the labels of the categories of "Tendency":
library("ggplot2")
library("RColorBrewer")
p <- plotVar(x = ctg$Mean, y = ctg$Tendency, plot_type = "density",
x_label = "Mean of the histogram ('Mean')",
y_label = "Histogram tendency ('Tendency')",
plot_title = "Relationship between 'Mean' and 'Tendency'") +
scale_color_manual(values = brewer.pal(n = 3, name = "Set2"),
labels = c("left asymmetric", "symmetric",
"right asymmetric")) +
scale_linetype_manual(values = rep(1, 3),
labels = c("left asymmetric", "symmetric",
"right asymmetric"))
p
## # Save as PDF:
## ggsave(file="mypathtofolder/FigureXY1.pdf", width=10, height=7)
}
Run the code above in your browser using DataLab