Learn R Programming

insurancerating (version 0.6.3)

autoplot.univariate: Automatically create a ggplot for objects obtained from univariate()

Description

Takes an object produced by univariate(), and plots the available input.

Usage

# S3 method for univariate
autoplot(
  object,
  show_plots = 1:9,
  ncol = 1,
  background = TRUE,
  labels = TRUE,
  sort = FALSE,
  sort_manual = NULL,
  dec.mark = ",",
  color = "dodgerblue",
  color_bg = "#E7B800",
  label_width = 10,
  coord_flip = FALSE,
  ...
)

Arguments

object

univariate object produced by univariate()

show_plots

numeric vector of plots to be shown (default is c(1,2,3,4,5,6,7,8,9)), there are nine available plots:

  • 1. frequency (i.e. number of claims / exposure)

  • 2. average severity (i.e. severity / number of claims)

  • 3. risk premium (i.e. severity / exposure)

  • 4. loss ratio (i.e. severity / premium)

  • 5. average premium (i.e. premium / exposure)

  • 6. exposure

  • 7. severity

  • 8. nclaims

  • 9. premium

ncol

number of columns in output (default is 1)

background

show exposure as a background histogram (default is TRUE)

labels

show labels with the exposure (default is TRUE)

sort

sort (or order) risk factor into descending order by exposure (default is FALSE)

sort_manual

sort (or order) risk factor into own ordering; should be a character vector (default is NULL)

dec.mark

control the format of the decimal point, as well as the mark between intervals before the decimal point, choose either "," (default) or "."

color

change the color of the points and line ("dodgerblue" is default)

color_bg

change the color of the histogram ("#E7B800" is default)

label_width

width of labels on the x-axis (10 is default)

coord_flip

flip cartesian coordinates so that horizontal becomes vertical, and vertical, horizontal (default is FALSE)

...

other plotting parameters to affect the plot

Value

a ggplot2 object

Examples

Run this code
# NOT RUN {
library(ggplot2)
x <- univariate(MTPL2, x = area, severity = amount, nclaims = nclaims, exposure = exposure)
autoplot(x)
autoplot(x, show_plots = c(6,1), background = FALSE, sort = TRUE)

MTPL2a <- MTPL2
MTPL2a$jaar <- sample(2015:2019, nrow(MTPL2a), replace = TRUE)
x1 <- univariate(MTPL2a, x = area, severity = amount, nclaims = nclaims,
exposure = exposure, by = jaar)
autoplot(x1, show_plots = 1:2)

# }

Run the code above in your browser using DataLab