R: Count data at each location

compute_count {ggvis} | R Documentation

## Count data at each location

### Description

Count data at each location

### Usage

    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

    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()

[Package ggvis version 0.4.3 Index]