Skip to content

24-7 Today

Menu
  • Home
  • Ads Guide
  • Blogging
  • Sec Tips
  • SEO Strategies
Menu

Plotting Distributions in R

Posted on September 30, 2025 by 24-7

[This article was first published on Jason Bryer, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)


Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

When working with distributions in R, each distribution has four functions, namely:

  • dXXX – density function.
  • rXXX – generate random number from this distribution.
  • pXXX – returns the area to the left of the given value.
  • qXXX – returns the quantile for the given value/area.

Where XXX is the distribution name (e.g. norm, binom, t, etc.).

remotes::install_github('jbryer/VisualStats')

The VisualStats::plot_distributions() function will generate four plots representing the four R distribution functions. For each subplot points correspond to the first parameter of the corresponding function (note the subplot for the random rXXX function does not have points since this simply returns random values from that distribution). The arrows correspond to what that function will return.

library(VisualStats)
data('distributions', package="VisualStats")
plot_distributions(dist="norm",
                   xvals = c(-1, 0, 0.5),
                   xmin = -4,
                   xmax = 4)


The top two plots (dXXX and rXXX) plot the distribution. The bottom two plots are the cumulative density function for the given distribution. The CDF describes the probability that a random variable (X) will be less than or equal to a specific value (x), written as F(x) = P(X ≤ x). The CDF provides a complete view of a random variable’s distribution by accumulating probabilities up to that point.

plot_distributions(dist="binom",
                   xvals = c(1, 3),
                   xmin = 0,
                   xmax = 10,
                   args = list(size = 10, prob = 0.35))


The VisualStats package also has a Shiny application that allows you to interactively plot the 17 distributions available in base R.

Screenshot of the distributions Shiny application

Related

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

©2025 24-7 Today | Design: WordPress | Design: Facts