View source: R/compute_align.R
compute_align | R Documentation |
This compute function is often used in conjunction with
compute_count
, when used on data with a continuous x variable.
By default, the computed width will be equal to the resolution of the data,
or, in other words the smallest difference between two values in the data.
compute_align(x, var, length = NULL, align = 0.5, dir = "x")
x |
Dataset-like object to align. Built-in methods for data frames, grouped data frames and ggvis visualisations. |
var |
Name of variable to compute width of. |
length |
An absolute length to use. If |
align |
Where does the existing variable fall on the new bins? 0 = left edge, 0.5 = center, 1 = right edge. |
dir |
Direction, i.e. |
An absolute width for each x can be specified by using the width
argument. If width
is NULL (the default), it will use the resolution
of the data as the width.
The original data frame, with additional columns:
'dir'min_ |
left boundary of bin |
'dir'max_ |
right boundary of bin |
'dir'len_ |
width of bin |
compute_bin
For counting cases within ranges of
a continuous variable.
compute_count
For counting cases at specific values
of a variable.
mtcars %>% compute_count(~disp) %>% compute_align(~x_)
mtcars %>% compute_count(~mpg) %>% compute_align(~x_)
# Use a specific width
pressure %>% compute_count(~temperature) %>% compute_align(~x_)
pressure %>% compute_count(~temperature) %>% compute_align(~x_, length = 5)
# It doesn't matter whether you transform inside or outside of a vis
mtcars %>% compute_count(~cyl, ~wt) %>%
compute_align(~x_, length = .5) %>%
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()
# Varying align
mtcars %>%
ggvis(x = ~xmin_, x2 = ~xmax_, y = ~count_, y2 = 0) %>%
compute_count(~cyl, ~wt) %>%
compute_align(~x_, length = 0.5, align = input_slider(0, 1)) %>%
layer_rects()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.