# DAL ToolBox
# version 1.1.727
source("https://raw.githubusercontent.com/cefet-rj-dal/daltoolbox/main/jupyter.R")
#loading DAL
load_library("daltoolbox")
Loading required package: daltoolbox Registered S3 method overwritten by 'quantmod': method from as.zoo.data.frame zoo Attaching package: ‘daltoolbox’ The following object is masked from ‘package:base’: transform
load_library("ggplot2")
load_library("RColorBrewer")
#color palette
colors <- brewer.pal(4, 'Set1')
# setting the font size for all charts
font <- theme(text = element_text(size=16))
Loading required package: ggplot2 Loading required package: RColorBrewer
The following examples use random variables so that different data distribution can be better viewed.
# example: dataset to be plotted
example <- data.frame(exponential = rexp(100000, rate = 1),
uniform = runif(100000, min = 2.5, max = 3.5),
normal = rnorm(100000, mean=5))
head(example)
exponential | uniform | normal | |
---|---|---|---|
<dbl> | <dbl> | <dbl> | |
1 | 0.09155231 | 2.612075 | 5.085059 |
2 | 2.01816829 | 3.294267 | 4.457824 |
3 | 0.58176393 | 2.636868 | 4.982670 |
4 | 0.12511421 | 3.344929 | 6.220225 |
5 | 0.02524745 | 2.573040 | 5.234677 |
6 | 0.31813066 | 2.620384 | 3.070939 |
Visualize the distribution of a single continuous variable by dividing the x axis into bins and counting the number of observations in each bin. Histograms (geom_histogram()) display the counts with bars. More information: ?geom_histogram (R documentation)
load_library("dplyr")
grf <- plot_hist(example |> select(exponential),
label_x = "exponential", color=colors[1]) + font
options(repr.plot.width=5, repr.plot.height=4)
plot(grf)
Loading required package: dplyr Attaching package: ‘dplyr’ The following objects are masked from ‘package:stats’: filter, lag The following objects are masked from ‘package:base’: intersect, setdiff, setequal, union Using as id variables
Function $grid.arrange$ is used to position previously computed charts
grfe <- plot_hist(example |> select(exponential),
label_x = "exponential", color=colors[1]) + font
grfu <- plot_hist(example |> select(uniform),
label_x = "uniform", color=colors[1]) + font
grfn <- plot_hist(example |> select(normal),
label_x = "normal", color=colors[1]) + font
Using as id variables Using as id variables Using as id variables
load_library("gridExtra")
options(repr.plot.width=15, repr.plot.height=4)
grid.arrange(grfe, grfu, grfn, ncol=3)
Loading required package: gridExtra Attaching package: ‘gridExtra’ The following object is masked from ‘package:dplyr’: combine