Learn R Programming

incidence2 (version 0.2.2)

plot.incidence2: Plotting functions

Description

incidence2 includes two plotting functions to simplify graph creation.

Usage

# S3 method for incidence2
plot(
  x,
  fill = NULL,
  stack = TRUE,
  title = NULL,
  col_pal = vibrant,
  alpha = 0.7,
  color = NA,
  xlab = "",
  ylab = NULL,
  n_breaks = 6,
  show_cases = FALSE,
  border = "white",
  na_color = "grey",
  group_labels = TRUE,
  centre_ticks = FALSE,
  legend = c("right", "left", "bottom", "top", "none"),
  angle = 0,
  format = NULL,
  ...
)

facet_plot(x, ...)

# S3 method for incidence2 facet_plot( x, facets = NULL, stack = TRUE, fill = NULL, title = NULL, col_pal = vibrant, alpha = 0.7, color = NA, xlab = "", ylab = NULL, n_breaks = 3, show_cases = FALSE, border = "white", na_color = "grey", group_labels = TRUE, centre_ticks = FALSE, legend = c("bottom", "top", "left", "right", "none"), angle = 0, format = NULL, nrow = NULL, ... )

scale_x_incidence( x, n_breaks = 6, group_labels = TRUE, format = NULL, angle = 0, size = NULL, coord_equal = FALSE, ... )

Arguments

x

An incidence() object.

fill

Which variable to color plots by. If NULL no distinction if made for plot colors.

stack

A logical indicating if bars of multiple groups should be stacked, or displayed side-by-side. Only used if fill is not NULL.

title

Optional title for the graph.

col_pal

col_pal The color palette to be used for the groups; defaults to vibrant (see ?palettes).

alpha

The alpha level for color transparency, with 1 being fully opaque and 0 fully transparent; defaults to 0.7.

color

The color to be used for the borders of the bars; NA for invisible borders; defaults to NA.

xlab

The label to be used for the x-axis; empty by default.

ylab

The label to be used for the y-axis; by default, a label will be generated automatically according to the time interval used in incidence computation.

n_breaks

n_breaks the ideal number of breaks to be used for the x-axis labeling

show_cases

if TRUE (default: FALSE), then each observation will be colored by a border. The border defaults to a white border unless specified otherwise. This is normally used outbreaks with a small number of cases. Note: this can only be used if stack = TRUE

border

If show_cases is TRUE this represents the color used for the borders of the individual squares plotted (defaults to "white").

na_color

The colour to plot NA values in graphs (default: grey).

group_labels

group_labels a logical value indicating whether labels x axis tick marks are in week format YYYY-Www when plotting weekly incidence; defaults to TRUE.

centre_ticks

Should ticks on the x axis be centred on the bars. This only applies to intervals that produce unambiguous labels (i.e 1 day, 1 month, 1 quarter or 1 year). Defaults to FALSE.

legend

Position of legend in plot.

angle

Angle to rotate x-axis labels.

format

Character string of desired format. See ?strptime.

...

arguments passed to ggplot2::scale_x_date(), ggplot2::scale_x_datetime(), or ggplot2::scale_x_continuous(), depending on how the $date element is stored in the incidence object.

facets

Which variable to facet plots by. If NULL will use all group_labels of the incidence object.

nrow

Number of rows.

size

text size in pts.

coord_equal

Should the x and y axis display with equal ratio.

Value

Details

  • plot creates a one-pane graph of an incidence object.

  • facet_plot creates a multi-facet graph of a grouped incidence object. If the object has no groups it returns the same output as a call to plot().

  • If the incidence() object has a rolling average column then that average will be overlaid on top.

Examples

Run this code
# NOT RUN {
if (requireNamespace("outbreaks", quietly = TRUE)) {
  withAutoprint({
    data(ebola_sim_clean, package = "outbreaks")
    dat <- ebola_sim_clean$linelist

    inci <- incidence(dat,
                      date_index = date_of_onset,
                      interval = 7,
                      groups = hospital)

    inci2 <- incidence(dat,
                      date_index = date_of_onset,
                      interval = 7,
                      groups = c(hospital, gender))

    plot(inci)
    plot(inci, fill = hospital)
    plot(inci, fill = hospital, stack = FALSE)

    facet_plot(inci)
    facet_plot(inci2)
    facet_plot(inci2, facets = gender)
    facet_plot(inci2, facets = hospital, fill = gender)
  })
}
# }

Run the code above in your browser using DataLab