compute_count: Count data at each location

Description Usage Arguments Value See Also Examples

View source: R/compute_count.R

Description

Count data at each location

Usage

1
compute_count(x, x_var, w_var = NULL)

Arguments

x

Dataset-like object to count. Built-in methods for data frames, grouped data frames and ggvis visualisations.

x_var,w_var

Names of x and weight variables.

Value

A data frame with columns:

count_

the number of points

x_

the x value where the count was made

The width of each "bin" is set to the resolution of the data – that is, the smallest difference between two x values.

See Also

compute_bin For counting cases within ranges of a continuous variable.

compute_align For calculating the "width" of data.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
mtcars %>% compute_count(~cyl)

# Weight the counts by car weight value
mtcars %>% compute_count(~cyl, ~wt)

# If there's one weight value at each x, it effectively just renames columns.
pressure %>% compute_count(~temperature, ~pressure)
# Also get the width of each bin
pressure %>% compute_count(~temperature, ~pressure) %>% compute_align(~x_)

# It doesn't matter whether you transform inside or outside of a vis
mtcars %>% compute_count(~cyl, ~wt) %>%
  compute_align(~x_) %>%
  ggvis(x = ~xmin_, x2 = ~xmax_, y = ~count_, y2 = 0) %>%
  layer_rects()

mtcars %>%
  ggvis(x = ~xmin_, x2 = ~xmax_, y = ~count_, y2 = 0) %>%
  compute_count(~cyl, ~wt) %>%
  compute_align(~x_) %>%
  layer_rects()

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