layer_densities: Transformation: density estimate

Description Usage Arguments Examples

View source: R/layer_densities.R

Description

transform_density is a data transformation that computes a kernel density estimate from a dataset. layer_density combines transform_density with mark_path and mark_area to display a smooth line and its standard errror.

Usage

1
2
layer_densities(vis, ..., kernel = "gaussian", adjust = 1,
  density_args = list(), area = TRUE)

Arguments

vis

The visualisation to modify

...

Visual properties, passed on to props.

kernel

Smoothing kernel. See density for details.

adjust

Multiple the default bandwidth by this amount. Useful for controlling wiggliness of density.

density_args

Other arguments passed on to compute_density and thence to density.

area

Should there be a shaded region drawn under the curve?

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Basic density estimate
faithful %>% ggvis(~waiting) %>% layer_densities()
faithful %>% ggvis(~waiting) %>% layer_densities(area = FALSE)

# Control bandwidth with adjust
faithful %>% ggvis(~waiting) %>% layer_densities(adjust = .25)
faithful %>% ggvis(~waiting) %>%
  layer_densities(adjust = input_slider(0.1, 5))

# Control stroke and fill
faithful %>% ggvis(~waiting) %>%
  layer_densities(stroke := "red", fill := "red")

# With groups
PlantGrowth %>% ggvis(~weight, fill = ~group) %>% group_by(group) %>%
  layer_densities()
PlantGrowth %>% ggvis(~weight, stroke = ~group) %>% group_by(group) %>%
  layer_densities(strokeWidth := 3, area = FALSE)

rpruim/ggvis2 documentation built on May 28, 2019, 2:34 a.m.