Skip to contents

Create barplots to show real cases and the predictions of the function diseasenowcasting::nowcast()

Usage

# S3 method for class 'nowcaster'
plot(
  x,
  color = "#5F7E62",
  datesbrakes = NULL,
  casesbrakes = 10,
  rowsfacet = NULL,
  colsfacet = NULL,
  quantiles = c(0.05, 0.95),
  title = NULL,
  ...
)

Arguments

x

The output of the nowcast() function

color

A string indicating the color for the barplots. Works with the default R colors of grDevices::colors(). Hex color codes works as well. Best results with darker colors.

datesbrakes

A string giving the distance between x-axis breaks if not specified, one label per bar. Other valid examples are: "2 weeks", or "10 years", 'sec', 'min', 'hour', 'day', 'week', 'month', 'year', optionally followed by 's'.

casesbrakes

Desired number of y-axis breaks. You may get slightly more or fewer breaks that requested due to dynamic adaptation.

rowsfacet

Number of rows for arranging facets when using ggplot2::facet_wrap(). It allows manual control over the layout of multiple strata in the plot.

colsfacet

Number of columns for arranging facets when using ggplot2::facet_wrap(). It allows manual control over the layout of multiple strata in the plot.

quantiles

a vector of two values to specify the quantiles for the error bars.

title

string to add as a title of the plot

...

Additional parameters to pass to your plot

Value

A ggplot2::ggplot2() object with barplots to show real cases and the predictions of the function nowcast(). It creates a facet for each strata.

Examples

# Load the data
data(denguedat)

# Run a nowcast with very few iterations
# change to method = "sampling" when working and remove the iter = 10 (or set to iter = 2000)
now <- as.Date("1990-10-01")

# perform nowcasting
ncast <- nowcast(denguedat, "onset_week", "report_week",strata = "gender",
                      now = now, method = "optimization",
                      seed = 2495624, iter = 10
                      )


# plot results requires ggplot2 package
if (!requireNamespace("ggplot2", quietly = TRUE)){
  plot(ncast)

  # other plotting options
  plot(ncast, rowsfacet = 2,
       datesbrakes = "2 weeks", casesbrakes = 15,
       color = "deepskyblue3")
}