jaspHistogram.Rd
A plot histogram with three components.
(1) A histogram, which can be tweaks with the same settings as hist
.
(2) A density line, which can optionally be shaded.
(3) rugs underneath the figure.
Each of these components can be enabled (or disabled) individually.
Colors are taken from graphOptions("palette")
.
jaspHistogram(
x,
xName,
groupingVariable = NULL,
groupingVariableName,
histogram = TRUE,
histogramPosition = "dodge",
binWidthType = c("doane", "fd", "scott", "sturges", "manual"),
numberOfBins = NA,
rugs = FALSE,
rugsColor = FALSE,
density = FALSE,
densityColor = FALSE,
densityShade = FALSE,
densityShadeAlpha = 0.6,
densityLineWidth = 1,
hideYAxisLabels = density
)
numeric, the data to show a histogram for
string, the title on the x-axis
factor, show histograms and/ or densities for individual groups?
character, legend name of the grouping variable.
logical, should a histogram be shown?
character, see argument position
in geom_histogram
.
string, type of bindwidth, matches the string values that can be passed to hist
.
if binWidthType is set to "manual", this value determines the number of bins.
logical, should rugs be shown on the x-axis?
logical, should the rugs be colored?
logical, should a density be superimposed on the plot?
logical, should the density be colored?
logical, should the area underneath the density be shaded?
numeric in [0, 1], transparancy for the shaded density.
positive number, the line width of the superimposed density.
logical, should the y-axis line be hidden? Defaults to showDensity
.
set.seed(1234)
# some random data
x <- rnorm(1e3) + rnorm(1e3, 1, .1) - rgamma(1e3, 10, 5)
# individual plot components can be enabled or disabled
jaspHistogram(x, "random data", histogram = TRUE, density = FALSE, rugs = FALSE) +
ggplot2::ggtitle("default options")
#> Warning: The dot-dot notation (`..count..`) was deprecated in ggplot2 3.4.0.
#> ℹ Please use `after_stat(count)` instead.
#> ℹ The deprecated feature was likely used in the jaspGraphs package.
#> Please report the issue to the authors.
jaspHistogram(x, "random data", histogram = TRUE, density = TRUE, rugs = FALSE)
#> Warning: Removed 12 rows containing missing values or values outside the scale range
#> (`geom_line()`).
jaspHistogram(x, "random data", histogram = TRUE, density = TRUE, rugs = TRUE)
#> Warning: Removed 12 rows containing missing values or values outside the scale range
#> (`geom_line()`).
jaspHistogram(x, "random data", histogram = TRUE, density = FALSE, rugs = TRUE)
jaspHistogram(x, "random data", histogram = FALSE, density = FALSE, rugs = TRUE)
jaspHistogram(x, "random data", histogram = FALSE, density = FALSE, rugs = FALSE) +
ggplot2::ggtitle("this is a bit boring though")
# histogram style can be tweaked
jaspHistogram(x, binWidthType = "sturges") + ggplot2::ggtitle("breaks: sturges")
jaspHistogram(x, binWidthType = "manual", numberOfBins = 250) +
ggplot2::ggtitle("breaks: manual")
# split by group
groupingVariable <- gl(3, 333, length = 1e3)
groupingVariableName <- "group name"
jaspHistogram(x, "random data", groupingVariable, groupingVariableName)
jaspHistogram(x, "random data", groupingVariable, groupingVariableName,
histogramPosition = "identity") # stacked
jaspHistogram(x, "random data", groupingVariable, groupingVariableName, density = TRUE,
rugs = TRUE, rugsColor = TRUE)
#> Warning: Removed 12 rows containing missing values or values outside the scale range
#> (`geom_line()`).
jaspHistogram(x, "random data", groupingVariable, groupingVariableName, density = TRUE,
rugs = TRUE, hideYAxisLabels = FALSE)
#> Warning: Removed 12 rows containing missing values or values outside the scale range
#> (`geom_line()`).
jaspHistogram(x, "random data", groupingVariable, groupingVariableName, density = TRUE,
densityColor = TRUE, hideYAxisLabels = FALSE, densityLineWidth = 2)
#> Warning: Removed 31 rows containing missing values or values outside the scale range
#> (`geom_line()`).
# Can also be used to make fancy density plots
data("mtcars")
graphOptions(palette = "viridis")
jaspHistogram(mtcars$drat, "drat", factor(mtcars$cyl), "cyl",
histogram = FALSE, hideYAxisLabels = FALSE,
density = TRUE, densityColor = TRUE, densityShade = TRUE, densityShadeAlpha = 0.45
)
#> Warning: Removed 186 rows containing missing values or values outside the scale range
#> (`geom_line()`).
graphOptions(palette = "colorblind")