File: compute_align.Rd

package info (click to toggle)
r-cran-ggvis 0.4.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,716 kB
  • sloc: javascript: 7,373; sh: 25; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 2,509 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/compute_align.R
\name{compute_align}
\alias{compute_align}
\title{Align positions using length.}
\usage{
compute_align(x, var, length = NULL, align = 0.5, dir = "x")
}
\arguments{
\item{x}{Dataset-like object to align. Built-in methods for data frames,
grouped data frames and ggvis visualisations.}

\item{var}{Name of variable to compute width of.}

\item{length}{An absolute length to use. If \code{NULL} (the default), the
width will be equivalent to the resolution of the data.}

\item{align}{Where does the existing variable fall on the new bins?
0 = left edge, 0.5 = center, 1 = right edge.}

\item{dir}{Direction, i.e. \code{"x"} or \code{"y"}. Used to generate
variable names in output.}
}
\value{
The original data frame, with additional columns:
 \item{'dir'min_}{left boundary of bin}
 \item{'dir'max_}{right boundary of bin}
 \item{'dir'len_}{width of bin}
}
\description{
This compute function is often used in conjunction with
\code{\link{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.
}
\details{
An absolute width for each x can be specified by using the \code{width}
argument. If \code{width} is NULL (the default), it will use the resolution
of the data as the width.
}
\examples{
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()
}
\seealso{
\code{\link{compute_bin}} For counting cases within ranges of
  a continuous variable.

\code{\link{compute_count}} For counting cases at specific values
  of a variable.
}