Compute density of data.

Description

Compute density of data.

Usage

1
2
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

1
2
3
4
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_)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.