Description Usage Arguments Value Examples
View source: R/compute_density.R
Compute density of data.
1 2 |
x |
Dataset (data frame, |
x_var, w_var |
Names of variables to use for x position, and for weights. |
kernel |
Smoothing kernel. See |
trim |
If |
n |
Number of points (along x) to use in the density estimate. |
na.rm |
If |
... |
Additional arguments passed on to |
A data frame with columns:
pred_ |
regularly spaced grid of |
resp_ |
density estimate |
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_)
|
pred_ resp_
1 2.969963 1.142299e-04
2 12.559981 3.648257e-02
3 22.150000 5.285952e-02
4 31.740019 1.843844e-02
5 41.330037 6.481419e-05
# A tibble: 15 x 3
# Groups: cyl [3]
cyl pred_ resp_
<dbl> <dbl> <dbl>
1 4 13.862190 0.0003608151
2 4 20.756095 0.0557316200
3 4 27.650000 0.0570477944
4 4 34.543905 0.0317105107
5 4 41.437810 0.0001868163
6 6 15.140627 0.0009707982
7 6 17.370314 0.1127744633
8 6 19.600000 0.1908332694
9 6 21.829686 0.1446388632
10 6 24.059373 0.0010594070
11 8 8.201102 0.0008757959
12 8 11.500551 0.0272083941
13 8 14.800000 0.2223223191
14 8 18.099449 0.0649711085
15 8 21.398898 0.0004829170
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.