| Type: | Package |
| Title: | Visualize Probability Distributions |
| Version: | 0.2.2 |
| Description: | Visualize and compute percentiles/probabilities of normal, t, f, chi square and binomial distributions. |
| Depends: | R (≥ 4.1.0) |
| Imports: | ggplot2, grid, scales, stats, utils |
| Suggests: | covr, knitr, png, ragg, rmarkdown, testthat, vdiffr, xplorerr |
| License: | MIT + file LICENSE |
| URL: | https://github.com/rsquaredacademy/vistributions, https://vistributions.rsquaredacademy.com |
| BugReports: | https://github.com/rsquaredacademy/vistributions/issues |
| Encoding: | UTF-8 |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-21 04:51:03 UTC; DELL |
| Author: | Aravind Hebbali [aut, cre] |
| Maintainer: | Aravind Hebbali <aravindhebbali@rsquaredacademy.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-11-23 07:40:02 UTC |
vistributions package
Description
Visualize probability distributions.
Author(s)
Maintainer: Aravind Hebbali aravindhebbali@rsquaredacademy.com
Authors:
Aravind Hebbali aravindhebbali@rsquaredacademy.com
See Also
Useful links:
Report bugs at https://github.com/rsquaredacademy/vistributions/issues
Visualize binomial distribution
Description
Visualize how changes in number of trials and the probability of success affect the shape of the binomial distribution. Compute & visualize probability from a given quantile and quantiles out of given probability.
Usage
vdist_binom_plot(n = 10, p = 0.3, print_plot = TRUE)
vdist_binom_prob(
n = 10,
p = 0.3,
s = 4,
type = c("lower", "upper", "exact", "interval"),
print_plot = TRUE
)
vdist_binom_perc(
n = 10,
p = 0.5,
tp = 0.05,
type = c("lower", "upper"),
print_plot = TRUE
)
Arguments
n |
Number of trials (a single non-negative whole number). |
p |
Probability of success in each trial. |
print_plot |
logical; if |
s |
Number of successes: whole numbers in |
type |
Lower/upper/exact/interval. |
tp |
Tail probability for quantile calculation, strictly between 0 and
1. The cutoff follows |
Details
Probabilities below 1e-10% (including underflows) are shown as
< 1e-10%, with the corresponding upper display > 99.9999999999%.
A probability below one that rounds to 1.000 at three decimals is
shown as > 0.999 when it is at most 1 - 1e-12;
above that threshold it uses the percentage bound. Exact certainty is
shown as = 1.000.
Every bar is one count while n + 1 counts fit in the plotting
grid (2001 bars). A wider support is drawn in approximately 2001 bins
of counts; event boundaries can split up to two bins, each bar showing the exact probability of its bin, with a caption
that discloses the grouping; the grid therefore has a bounded number of
points whatever n is. Probabilities, quantiles and shaded masses always
come from dbinom(), pbinom() and qbinom().
Value
An object of class ggplot (invisibly if print_plot = TRUE).
See Also
Examples
# visualize binomial distribution
vdist_binom_plot(10, 0.3)
# visualize probability from a given quantile
vdist_binom_prob(10, 0.3, 4, type = 'exact')
vdist_binom_prob(10, 0.3, 4, type = 'lower')
vdist_binom_prob(10, 0.3, 4, type = 'upper')
vdist_binom_prob(10, 0.3, c(4, 6), type = 'interval')
# visualize quantiles out of given probability
vdist_binom_perc(10, 0.5, 0.05)
vdist_binom_perc(10, 0.5, 0.05, "upper")
Visualize chi square distribution
Description
Visualize how changes in degrees of freedom affect the shape of the chi square distribution. Compute & visualize quantiles out of given probability and probability from a given quantile.
Usage
vdist_chisquare_plot(
df = 3,
normal = FALSE,
xaxis_range = NULL,
print_plot = TRUE
)
vdist_chisquare_perc(
probs = 0.95,
df = 3,
type = c("lower", "upper"),
print_plot = TRUE
)
vdist_chisquare_prob(
perc = 13,
df = 11,
type = c("lower", "upper"),
print_plot = TRUE
)
Arguments
df |
Degrees of freedom (at least 0.1 and at most 2e20; need not be a
whole number). This is a conservative relative-resolution limit requiring
|
normal |
If |
xaxis_range |
Upper X axis limit; by default the view spans four
standard deviations around df, clipped at zero. An explicitly supplied
value must not exceed |
print_plot |
logical; if |
probs |
Probability value, strictly between 0 and 1 and within
|
type |
Lower tail or upper tail. |
perc |
Quantile value. |
Details
Percentages below 1e-10% are displayed as < 1e-10%, and
probabilities within 1e-10% of 100% as > 99.9999999999%. A
probability below 1 that would print 100.0% is displayed as the bound
> 99.9%, the mirror of the floor; an exact 1 keeps 100.0%.
Percentages at or above 0.1% keep at least one decimal. Smaller
percentages use three significant digits in scientific notation, retaining
trailing zeros (for example 5.00e-02%). Values that round to
0.1% at three significant digits use 1.00e-01% on either side
of the notation switch. Cutoffs retain enough digits that the same event prints identical
percentage text in the percentile and probability forms, including at
halfway rounding boundaries. Extra percentage digits resolve exact halfway
values (for example 5.05%).
Drawing contract: every probability, cutoff and caption is computed from the
chi-square density, distribution and quantile functions, never from the
drawn grid. The shading polygon starts at the support (zero), not at a
quantile floor, so no probability is discarded for small df; it
spans the whole event and its own area is checked against the exact event
probability (within 1e-6 relative error above the display floor). Where the density is unbounded at zero it is
capped on the display axis only: the source-coordinate area and the printed
probability always use the unclipped density. Captions use one rounding rule
and are true at the precision they print. A shaded region too narrow to
occupy a pixel at the plotted scale (for example the lower 5% tail of
df = 0.1) is marked with a visible strip in the panel and disclosed in
the caption; its polygon and its checked area are unchanged.
A shaded region whose height is less than 0.4% of the density peak is
disclosed as too small to display.
Every plotting grid has a bounded number of points, whatever the range or degrees of
freedom.
A probability view keeps the body of the distribution: when the requested
cutoff would leave less than 20% of the distribution inside the panel (for example
vdist_chisquare_prob(13, df = 200)), the window is widened to the mean
and a few standard deviations instead of showing a flat far tail.
An explicitly supplied xaxis_range is limited to 1e10;
wider explicit windows are rejected with an error naming xaxis_range.
df itself is limited to 2e20, a conservative relative-resolution
limit requiring sqrt(2 / df) >= 1e-10. This cap does not mark the
point at which the default window endpoints become identical.
Probability labels are anchored to the cutoff line with a fixed absolute
gap, so their layout does not depend on the device size. A label that would
leave the panel (a cutoff close to an edge) is stacked on a second line
instead of being drawn across the cutoff. Labels are drawn above the
density, the cutoff lines and the markers, each on a small light patch in the
panel background colour, so the shaded fill cannot erase the text and a
cutoff line cannot cross it.
Value
An object of class ggplot (invisibly if print_plot = TRUE).
See Also
Examples
# visualize chi square distribution
vdist_chisquare_plot()
vdist_chisquare_plot(df = 5)
vdist_chisquare_plot(df = 5, normal = TRUE)
# visualize quantiles out of given probability
vdist_chisquare_perc(0.165, 8, 'lower')
vdist_chisquare_perc(0.22, 13, 'upper')
# visualize probability from a given quantile.
vdist_chisquare_prob(13.58, 11, 'lower')
vdist_chisquare_prob(15.72, 13, 'upper')
Visualize f distribution
Description
Visualize how changes in degrees of freedom affect the shape of the F distribution. Compute & visualize quantiles out of given probability and probability from a given quantile.
Usage
vdist_f_plot(num_df = 4, den_df = 30, normal = FALSE, print_plot = TRUE)
vdist_f_perc(
probs = 0.95,
num_df = 3,
den_df = 30,
type = c("lower", "upper"),
print_plot = TRUE
)
vdist_f_prob(
perc = 2.35,
num_df = 5,
den_df = 32,
type = c("lower", "upper"),
print_plot = TRUE
)
Arguments
num_df |
Degrees of freedom associated with the numerator of f statistic (at least 1; need not be a whole number). |
den_df |
Degrees of freedom associated with the denominator of f statistic (positive; need not be a whole number). |
normal |
If |
print_plot |
logical; if |
probs |
Probability value, strictly between 0 and 1 and within
|
type |
Lower tail or upper tail. |
perc |
Quantile value. |
Details
Percentages below 1e-10% are displayed as < 1e-10%, and
probabilities within 1e-10% of 100% as > 99.9999999999%. A
probability below 1 that would print 100.0% is displayed as the bound
> 99.9%, the mirror of the floor; an exact 1 keeps 100.0%.
Percentages at or above 0.1% keep at least one decimal. Smaller
percentages use three significant digits in scientific notation, retaining
trailing zeros (for example 5.00e-02%). Values that round to
0.1% at three significant digits use 1.00e-01% on either side
of the notation switch. Cutoffs retain enough digits that the same event prints identical
percentage text in the percentile and probability forms, including at
halfway rounding boundaries. Extra percentage digits resolve exact halfway
values (for example 5.05%).
The F density must not be too concentrated to draw: the central
99.9998% probability mass must span a finite interval of at least 0.001.
More concentrated densities (for example num_df = den_df = 1e9) stop
with a clear error instead of returning an inaccurate shaded area. A tail
that does not converge at double precision (for example den_df = 0.01)
is reported as a tail-overflow error, separately from concentration.
Every probability, cutoff and caption is computed from the F density,
distribution and quantile functions, never from the drawn grid: the shading
polygon starts at the support and spans the whole event, and its own area is
checked against the exact event probability (within 1e-6 relative error above the display floor). Where the density
is unbounded at zero it is capped on the display axis only; the area check
and the printed probability always use the unclipped density.
Very wide heavy-tail windows are drawn on a symmetric log axis so the shaded
event stays visible. Captions use one rounding rule and are true at the
precision they print. When qf() fails to invert pf() to
relative 1e-6 in the smaller tail, the equivalent F-beta quantile is used. Quantiles may also
be refined by root finding, so equal
degrees of freedom up to at least 1e8 plot accurately. A shaded
region too narrow to occupy a pixel at the plotted scale is marked with a
visible strip in the panel and disclosed in the caption; its polygon and its
checked area are unchanged. Upper-tail views retain the density body and
disclose shaded mass outside the panel. A cutoff clipped to the panel edge
is also disclosed. Every plotting grid has a bounded number of
points, whatever the degrees of freedom or the cutoff. A shaded region whose
visible height is less than 0.4% of the density peak is disclosed in the
caption as too small to display. Probability labels are anchored to the
cutoff line with a fixed absolute gap, so their layout does not depend on the
device size; a label that would leave the panel is stacked on a second line
instead of being drawn across the cutoff. Labels are drawn above the density,
the cutoff lines and the markers, each on a small light patch in the panel
background colour, so the shaded fill cannot erase the text and a cutoff line
cannot cross it.
Value
An object of class ggplot (invisibly if print_plot = TRUE).
See Also
Examples
# visualize F distribution
vdist_f_plot()
vdist_f_plot(6, 10, normal = TRUE)
# visualize quantiles out of given probability
vdist_f_perc(0.95, 3, 30, 'lower')
vdist_f_perc(0.125, 9, 35, 'upper')
# visualize probability from a given quantile
vdist_f_prob(2.35, 5, 32)
vdist_f_prob(1.5222, 9, 35, type = "upper")
Launch shiny app
Description
Launches shiny app for visualizing distributions.
Usage
vdist_launch_app()
Value
Called for its side effect of launching the app; returns the app object invisibly.
Examples
## Not run:
vdist_launch_app ()
## End(Not run)
Visualize normal distribution
Description
Visualize how changes in mean and standard deviation affect the shape of the normal distribution. Compute & visualize quantiles out of given probability and probability from a given quantile.
Usage
vdist_normal_plot(mean = 0, sd = 1, print_plot = TRUE)
vdist_normal_perc(
probs = 0.95,
mean = 0,
sd = 1,
type = c("lower", "upper", "both"),
print_plot = TRUE
)
vdist_normal_prob(
perc = 3,
mean = 0,
sd = 1,
type = c("lower", "upper", "both"),
print_plot = TRUE
)
Arguments
mean |
Mean of the normal distribution. |
sd |
Standard deviation of the normal distribution. It must be positive.
When |
print_plot |
logical; if |
probs |
Probability value, strictly between 0 and 1 and within
|
type |
Lower tail, upper tail or both. |
perc |
Quantile value(s): a single value for a lower or upper tail, or
two values in nondecreasing order for the interval between them. Two
values select |
Details
Percentages below 1e-10% are displayed as < 1e-10%, and
probabilities within 1e-10% of 100% as > 99.9999999999%. A
probability below 1 that would print 100.0% is displayed as the bound
> 99.9%, the mirror of the floor; an exact 1 keeps 100.0%.
Percentages at or above 0.1% keep at least one decimal. Smaller
percentages use three significant digits in scientific notation, retaining
trailing zeros (for example 5.00e-02%). Values that round to
0.1% at three significant digits use 1.00e-01% on either side
of the notation switch. Cutoffs retain enough digits that the same event prints identical
percentage text in the percentile and probability forms, including at
halfway rounding boundaries. Extra percentage digits resolve exact halfway
values (for example 5.05%).
Supported values: for a central interval the representable endpoints
must enclose probs to within 1e-6 relative error. If not, increase
sd or choose a larger probs; ordinary inputs are unaffected.
Drawing contract: every probability, cutoff and caption is computed from the
normal density, distribution and quantile functions, never from the drawn
grid. The shaded polygon spans the whole event and is sampled on a grid
spaced in probability and in standardised units; its own area is checked
against the exact event probability and kept within 1e-6 relative error for events above the display floor. A percentage is
printed at a precision whose rounding interval contains the exact
probability, and the printed cutoffs reproduce that displayed percentage.
Because the normal is a location-scale family, multiplying mean and
sd by the same factor changes only the axis labels: the shaded
proportion, the probability caption and the standardised picture are the
same. A part of the shaded region that lies outside the plotted window is
disclosed in a plot caption. A shaded region too narrow to occupy a pixel at
the plotted scale (for example an extreme percentile of a concentrated
distribution) is marked with a visible strip in the panel and disclosed in
the caption; its polygon and its checked area are unchanged. Every plotting
grid has a bounded number of points, whatever the mean and standard
deviation.
A shaded region whose visible height is less than 0.4% of the density peak
is disclosed in the caption as too small to display.
Probability labels are anchored to the cutoff line with a fixed absolute
gap, so their layout does not depend on the device size. A label that would
leave the panel (a cutoff close to an edge) is stacked on a second line
instead of being drawn across the cutoff. Labels are drawn above the
density, the cutoff lines and the markers, each on a small light patch in the
panel background colour, so the shaded fill cannot erase the text and a
cutoff line cannot cross it.
Value
An object of class ggplot (invisibly if print_plot = TRUE).
See Also
Examples
# visualize normal distribution
vdist_normal_plot()
vdist_normal_plot(mean = 2, sd = 0.6)
# visualize quantiles out of given probability
vdist_normal_perc(0.95, mean = 2, sd = 1.36)
vdist_normal_perc(0.3, mean = 2, sd = 1.36, type = 'upper')
vdist_normal_perc(0.95, mean = 2, sd = 1.36, type = 'both')
# visualize probability from a given quantile
vdist_normal_prob(3.78, mean = 2, sd = 1.36)
vdist_normal_prob(3.43, mean = 2, sd = 1.36, type = 'upper')
vdist_normal_prob(c(-1.74, 1.83), type = 'both')
Visualize t distribution
Description
Visualize how degrees of freedom affect the shape of t distribution, visualize quantiles out of given probability and probability from a given quantile.
Usage
vdist_t_plot(df = 3, print_plot = TRUE)
vdist_t_perc(
probs = 0.95,
df = 4,
type = c("lower", "upper", "both"),
print_plot = TRUE
)
vdist_t_prob(
perc = 1.6,
df = 7,
type = c("lower", "upper", "interval", "both"),
print_plot = TRUE
)
Arguments
df |
Degrees of freedom, at least 0.05 (need not be a whole number).
Very small degrees of freedom make the tails so heavy that an ordinary
probability covers quantiles hundreds of orders of magnitude away, which
cannot be plotted at double precision; values below the documented floor
are rejected with an error naming |
print_plot |
logical; if |
probs |
Probability value, strictly between 0 and 1 and within
|
type |
Lower tail, upper tail, interval or both. |
perc |
Quantile value. For |
Details
Percentages below 1e-10% are displayed as < 1e-10%, and
probabilities within 1e-10% of 100% as > 99.9999999999%. A
probability below 1 that would print 100.0% is displayed as the bound
> 99.9%, the mirror of the floor; an exact 1 keeps 100.0%.
Percentages at or above 0.1% keep at least one decimal. Smaller
percentages use three significant digits in scientific notation, retaining
trailing zeros (for example 5.00e-02%). Values that round to
0.1% at three significant digits use 1.00e-01% on either side
of the notation switch. Cutoffs retain enough digits that the same event prints identical
percentage text in the percentile and probability forms, including at
halfway rounding boundaries. Extra percentage digits resolve exact halfway
values (for example 5.05%).
Drawing contract: every probability, cutoff and caption is computed from the
t density, distribution and quantile functions, never from the drawn grid.
The shaded polygon spans the whole event (clipped only by the panel) and is
sampled on a grid spaced in probability, with a fixed number of points; its
own area is checked against the exact event probability and kept within
1e-6 relative error for events above the display floor. Captions use one rounding rule and are true at the precision they
print. A very wide window - for example a heavy tail with a small df -
is drawn on a symmetric log axis so the shaded event stays visible; the
printed probability and the area check always use the unclipped density.
A shaded region too narrow to occupy a pixel at the plotted scale is marked
with a visible strip in the panel and disclosed in the caption; its polygon
and its checked area are unchanged. Every plotting grid has a bounded number
of points, whatever the degrees of freedom or the cutoff.
The joint limits on df, probs and perc leave enough
representable tail for the relative area check. Outside these limits an
error names the supplied argument and its valid range. Text labels are kept
inside the panel using their rendered glyph widths. A shaded region whose
visible height is less than 0.4% of the density peak is disclosed in the
caption as too small to display. Probability labels are anchored to the
cutoff line with a fixed absolute gap, so their layout does not depend on
the device size; a label that would leave the panel is stacked on a second
line instead of being drawn across the cutoff. Labels are drawn above the
density, the cutoff lines and the markers, each on a small light patch in the
panel background colour, so the shaded fill cannot erase the text and a
cutoff line cannot cross it.
Value
An object of class ggplot (invisibly if print_plot = TRUE).
See Also
Examples
# Visualize a distribution, percentile and probability.
vdist_t_plot()
vdist_t_perc(probs = 0.95, df = 4, type = 'lower')
vdist_t_perc(probs = 0.35, df = 4, type = 'upper')
vdist_t_prob(2.045, 7, 'lower')
vdist_t_prob(1.6, 7, 'both')
# Additional variants are exercised in the test suite.
## Not run:
vdist_t_plot(6)
vdist_t_perc(probs = 0.69, df = 7, type = 'both')
vdist_t_prob(0.945, 7, 'upper')
vdist_t_prob(1.445, 7, 'interval')
## End(Not run)