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.63     -3.26 0.000576 0.0516 -1.63    
#>  2 1              2  0.274    -3.11 0.00147  0.608   0.274   
#>  3 1              3 -0.000218 -2.97 0.00338  0.500  -0.000218
#>  4 1              4 -0.636    -2.83 0.00704  0.263  -0.636   
#>  5 1              5  1.17     -2.68 0.0132   0.878   1.17    
#>  6 1              6  1.02     -2.54 0.0225   0.846   1.02    
#>  7 1              7 -0.476    -2.40 0.0348   0.317  -0.476   
#>  8 1              8  1.30     -2.25 0.0492   0.903   1.30    
#>  9 1              9  1.26     -2.11 0.0640   0.895   1.26    
#> 10 1             10  0.700    -1.97 0.0779   0.758   0.700   
#> # ℹ 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")