layer_histograms {ggvis}R Documentation

Display binned data

Description

Display binned data

Usage

layer_histograms(
  vis,
  ...,
  width = NULL,
  center = NULL,
  boundary = NULL,
  closed = c("right", "left"),
  stack = TRUE,
  binwidth
)

layer_freqpolys(
  vis,
  ...,
  width = NULL,
  center = NULL,
  boundary = NULL,
  closed = c("right", "left"),
  binwidth
)

Arguments

vis

Visualisation to modify

...

Visual properties used to override defaults.

width

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.

center

The center of one of the bins. Note that if center is above or below the range of the data, things will be shifted by an appropriate number of widths. To center on integers, for example, use width=1 and center=0, even if 0 is outside the range of the data. At most one of center and boundary may be specified.

boundary

A boundary between two bins. As with center, things are shifted when boundary is outside the range of the data. For example, to center on integers, use width = 1 and boundary = 0.5, even if 1 is outside the range of the data. At most one of center and boundary may be specified.

closed

One of "right" or "left" indicating whether right or left edges of bins are included in the bin.

stack

If TRUE, will automatically stack overlapping bars.

binwidth

Deprecated; use width instead.

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

# Create histograms and frequency polygons with layers
mtcars %>% ggvis(~mpg) %>% layer_histograms()
mtcars %>% ggvis(~mpg) %>% layer_histograms(width = 2)
mtcars %>% ggvis(~mpg) %>% layer_freqpolys(width = 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(width = 2)
mtcars %>% ggvis(~mpg, stroke = ~factor(cyl)) %>% group_by(cyl) %>%
  layer_freqpolys(width = 2)

[Package ggvis version 0.4.9 Index]