Skip to contents

Example

This is a basic example which shows you how easy it is to generate data with TidyDensity:

library(TidyDensity)
library(dplyr)
library(ggplot2)

tidy_normal()
#> # A tibble: 50 × 7
#>    sim_number     x      y    dx       dy      p      q
#>    <fct>      <int>  <dbl> <dbl>    <dbl>  <dbl>  <dbl>
#>  1 1              1 -1.52  -3.17 0.000315 0.0640 -1.52 
#>  2 1              2 -0.835 -3.04 0.000857 0.202  -0.835
#>  3 1              3  0.251 -2.90 0.00213  0.599   0.251
#>  4 1              4  1.50  -2.76 0.00481  0.933   1.50 
#>  5 1              5  0.677 -2.63 0.00993  0.751   0.677
#>  6 1              6 -1.04  -2.49 0.0188   0.150  -1.04 
#>  7 1              7 -1.92  -2.35 0.0326   0.0272 -1.92 
#>  8 1              8  1.11  -2.21 0.0520   0.866   1.11 
#>  9 1              9 -0.568 -2.08 0.0766   0.285  -0.568
#> 10 1             10 -0.257 -1.94 0.104    0.399  -0.257
#> # ℹ 40 more rows

An example plot of the tidy_normal data.

tn <- tidy_normal(.n = 100, .num_sims = 6)

tidy_autoplot(tn, .plot_type = "density")

tidy_autoplot(tn, .plot_type = "quantile")

tidy_autoplot(tn, .plot_type = "probability")

tidy_autoplot(tn, .plot_type = "qq")

We can also take a look at the plots when the number of simulations is greater than nine. This will automatically turn off the legend as it will become too noisy.

tn <- tidy_normal(.n = 100, .num_sims = 20)

tidy_autoplot(tn, .plot_type = "density")

tidy_autoplot(tn, .plot_type = "quantile")

tidy_autoplot(tn, .plot_type = "probability")

tidy_autoplot(tn, .plot_type = "qq")