Learn R Programming

billboarder (version 0.5.2)

bb_densityplot: Helper for creating a density plot

Description

Helper for creating a density plot

Usage

bb_densityplot(
  bb,
  data,
  mapping = NULL,
  stacked = FALSE,
  stat = "density",
  fill = FALSE,
  ...
)

Value

A `billboard` `htmlwidget` object.

Arguments

bb

A `billboard` `htmlwidget` object.

data

A `data.frame` or a `vector`, the first column will be used to calculate density if `x` is `NULL`.

mapping

Mapping of variables on the chart, see [bbaes()].

stacked

Logical, create a stacked density plot.

stat

Stat to compute: `density` or `count`.

fill

Produce a conditional density estimate, this option force `stacked = TRUE`.

...

Arguments passed to [stats::density()].

See Also

[bb_histogram()]

Examples

Run this code
# With a vector
billboarder() %>%
  bb_densityplot(data = rnorm(1e4))

data("diamonds", package = "ggplot2")

# density plot with one variable
billboarder() %>%
  bb_densityplot(data = diamonds, x = "carat")

# Same with mapping
billboarder() %>%
  bb_densityplot(diamonds, bbaes(carat))

# With a grouping variable
billboarder() %>%
  bb_densityplot(data = diamonds, x = "depth", group = "cut") %>%
  bb_x_axis(min = 55, max = 70)

# Same with mapping
billboarder() %>%
  bb_densityplot(diamonds, bbaes(depth, group = cut)) %>%
  bb_x_axis(min = 55, max = 70)

# a stacked density plot using count as statistic
bb <- billboarder() %>%
  bb_densityplot(
    diamonds, bbaes(depth, group = cut),
    stacked = TRUE, stat = "count"
  ) %>%
  bb_x_axis(min = 55, max = 70)
bb

# changing order
bb %>% bb_data(order = "asc")

Run the code above in your browser using DataLab