Learn R Programming

ggvis (version 0.4.1)

compute_density: 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
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

Run this code
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_)

Run the code above in your browser using DataLab