compute_density {ggvis}R Documentation

Compute density of data.

Description

Compute density of data.

Usage

compute_density(
  x,
  x_var,
  w_var = NULL,
  kernel = "gaussian",
  trim = FALSE,
  n = 256L,
  na.rm = FALSE,
  ...
)

Arguments

x

Dataset (data frame, grouped_df or ggvis) object to work with.

x_var, w_var

Names of variables to use for x position, and for weights.

kernel

Smoothing kernel. See density for details.

trim

If TRUE, the default, density estimates are trimmed to the actual range of the data. If FALSE, they are extended by the default 3 bandwidths (as specified by the cut parameter to density).

n

Number of points (along x) to use in the density estimate.

na.rm

If TRUE missing values will be silently removed, otherwise they will be removed with a warning.

...

Additional arguments passed on to density.

Value

A data frame with columns:

pred_

regularly spaced grid of n locations

resp_

density estimate

Examples

mtcars %>% compute_density(~mpg, n = 5)
mtcars %>% group_by(cyl) %>% compute_density(~mpg, n = 5)
mtcars %>% ggvis(~mpg) %>% compute_density(~mpg, n = 5) %>%
  layer_points(~pred_, ~resp_)

[Package ggvis version 0.4.9 Index]