Learn R Programming

ggvis (version 0.3.0.1)

layer_histograms: Display binned data

Description

Display binned data

Usage

layer_histograms(vis, ..., binwidth = NULL, origin = NULL, right = TRUE,
  stack = TRUE)

layer_freqpolys(vis, ..., binwidth = NULL, origin = NULL, right = TRUE)

Arguments

vis
Visualisation to modify
...
Visual properties used to override defaults.
stack
If TRUE, will automatically stack overlapping bars.
binwidth
The width of the bins. The default is NULL, which yields 30 bins that cover the range of the data. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data.
origin
The initial position of the left-most bin. If NULL, the the default, will use the smallest value in the dataset.
right
Should bins be right-open, left-closed, or right-closed, left-open.

See Also

layer_bars For bar graphs of counts at each unique x value, in contrast to a histogram's bins along x ranges.

Examples

Run this code
# Create histograms and frequency polygons with layers
mtcars %>% ggvis(~mpg) %>% layer_histograms()
mtcars %>% ggvis(~mpg) %>% layer_histograms(binwidth = 2)
mtcars %>% ggvis(~mpg) %>% layer_freqpolys(binwidth = 2)

# These are equivalent to combining compute_bin with the corresponding
# mark
mtcars %>% compute_bin(~mpg) %>% ggvis(~x_, ~count_) %>% layer_paths()

# With grouping
mtcars %>% ggvis(~mpg, fill = ~factor(cyl)) %>% group_by(cyl) %>%
  layer_histograms(binwidth = 2)
mtcars %>% ggvis(~mpg, stroke = ~factor(cyl)) %>% group_by(cyl) %>%
  layer_freqpolys(binwidth = 2)

Run the code above in your browser using DataLab