plot_pop: Add Population Line(s) to an Existing Grid

Description Usage Arguments Details Value Examples

View source: R/plot_functions.R

Description

This function adds one or multiple linearized CDFs to an existing plot grid.

Usage

1
2
3
4
5
6
7
8
9
plot_pop(
  p_obj = NULL,
  x,
  dist_params_tbl,
  distribution = c("weibull", "lognormal", "loglogistic", "normal", "logistic", "sev"),
  tol = 1e-06,
  title_trace = "Population",
  plot_method = c("plotly", "ggplot2")
)

Arguments

p_obj

A plot object to which the population lines are added or NULL. If NULL the population lines are plotted in an empty grid.

x

A numeric vector of length two or greater used for the x coordinates of the population line. If length(x) == 2 a sequence of length 200 between x[1] and x[2] is created. This sequence is equidistant with respect to the scale of the x axis. If length(x) > 2 the elements of x are the x coordinates of the population line.

dist_params_tbl

A tibble. See 'Details'.

distribution

Supposed distribution of the random variable. In the context of this function "weibull", "lognormal" and "loglogistic" stand for the two- and the three-parametric version of the respective distribution. The distinction is made via dist_params_tbl.

tol

The failure probability is restricted to the interval [tol, 1 - tol]. The default value is in accordance with the decimal places shown in the hover for plot_method = "plotly".

title_trace

A character string which is assigned to the trace shown in the legend.

plot_method

Plot package, which produces the visual output. Only used with p_obj = NULL, otherwise p_obj is used to determine the plot method.

Details

dist_params_tbl is a data.frame with two or three columns. For location-scale distributions the first column contains the location parameter and the second column contains the scale parameter. For three-parametric distributions the third column contains the threshold parameter.

If only one population line should be displayed, a numeric vector of length two or three is also supported (c(loc, sc) or c(loc, sc, thres)).

Value

A plot object which contains the linearized CDF(s).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
x <- rweibull(n = 100, shape = 1, scale = 20000)

# Example 1 - Two-parametric straight line:
pop_weibull <- plot_pop(
  p_obj = NULL,
  x = range(x),
  dist_params_tbl = c(log(20000), 1),
  distribution = "weibull"
)

# Example 2 - Three-parametric curved line:
x2 <- rweibull(n = 100, shape = 1, scale = 20000) + 5000

pop_weibull_2 <- plot_pop(
  p_obj = NULL,
  x = x2,
  dist_params_tbl = c(log(20000 - 5000), 1, 5000),
  distribution = "weibull"
)

# Example 3 - Multiple lines:
pop_weibull_3 <- plot_pop(
  p_obj = NULL,
  x = x,
  dist_params_tbl = data.frame(
    p_1 = c(log(20000), log(20000), log(20000)),
    p_2 = c(1, 1.5, 2)
    ),
  distribution = "weibull",
  plot_method = "ggplot2"
)

# Example 4 - Compare two- and three-parametric distributions:
pop_weibull_4 <- plot_pop(
  p_obj = NULL,
  x = x,
  dist_params_tbl = data.frame(
    param_1 = c(log(20000), log(20000)),
    param_2 = c(1, 1),
    param_3 = c(NA, 2)
  ),
  distribution = "weibull"
)

weibulltools documentation built on Jan. 16, 2021, 5:21 p.m.