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.11   -3.03 0.000342 0.133 -1.11  
#>  2 1              2  0.368  -2.91 0.000946 0.644  0.368 
#>  3 1              3 -0.356  -2.79 0.00232  0.361 -0.356 
#>  4 1              4 -0.463  -2.67 0.00507  0.322 -0.463 
#>  5 1              5  1.71   -2.55 0.00983  0.957  1.71  
#>  6 1              6 -0.221  -2.43 0.0170   0.413 -0.221 
#>  7 1              7 -0.0446 -2.31 0.0261   0.482 -0.0446
#>  8 1              8  0.135  -2.19 0.0358   0.554  0.135 
#>  9 1              9  0.213  -2.07 0.0441   0.584  0.213 
#> 10 1             10 -0.808  -1.95 0.0496   0.210 -0.808 
#> # … with 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")