Debian Codegraph @

man/brushedPoints.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/image-interact.R
3 \name{brushedPoints}
4 \alias{brushedPoints}
5 \alias{nearPoints}
6 \title{Find rows of data selected on an interactive plot.}
7 \usage{
8 brushedPoints(
9 df,
10 brush,
11 xvar = NULL,
12 yvar = NULL,
13 panelvar1 = NULL,
14 panelvar2 = NULL,
15 allRows = FALSE
16 )
17
18 nearPoints(
19 df,
20 coordinfo,
21 xvar = NULL,
22 yvar = NULL,
23 panelvar1 = NULL,
24 panelvar2 = NULL,
25 threshold = 5,
26 maxpoints = NULL,
27 addDist = FALSE,
28 allRows = FALSE
29 )
30 }
31 \arguments{
32 \item{df}{A data frame from which to select rows.}
33
34 \item{brush, coordinfo}{The data from a brush or click/dblclick/hover event
35 e.g. \code{input$plot_brush}, \code{input$plot_click}.}
36
37 \item{xvar, yvar}{A string giving the name of the variable on the x or y axis.
38 These are only required for base graphics, and must be the name of
39 a column in \code{df}.}
40
41 \item{panelvar1, panelvar2}{A string giving the name of a panel variable.
42 For expert use only; in most cases these will be automatically
43 derived from the ggplot2 spec.}
44
45 \item{allRows}{If \code{FALSE} (the default) return a data frame containing
46 the selected rows. If \code{TRUE}, the input data frame will have a new
47 column, \code{selected_}, which indicates whether the row was selected or not.}
48
49 \item{threshold}{A maximum distance (in pixels) to the pointer location.
50 Rows in the data frame will be selected if the distance to the pointer is
51 less than \code{threshold}.}
52
53 \item{maxpoints}{Maximum number of rows to return. If \code{NULL} (the default),
54 will return all rows within the threshold distance.}
55
56 \item{addDist}{If TRUE, add a column named \code{dist_} that contains the
57 distance from the coordinate to the point, in pixels. When no pointer
58 event has yet occurred, the value of \code{dist_} will be \code{NA}.}
59 }
60 \value{
61 A data frame based on \code{df}, containing the observations selected by the
62 brush or near the click event. For \code{nearPoints()}, the rows will be sorted
63 by distance to the event.
64
65 If \code{allRows = TRUE}, then all rows will returned, along with a new
66 \code{selected_} column that indicates whether or not the point was selected.
67 The output from \code{nearPoints()} will no longer be sorted, but you can
68 set \code{addDist = TRUE} to get an additional column that gives the pixel
69 distance to the pointer.
70 }
71 \description{
72 \code{brushedPoints()} returns rows from a data frame which are under a brush.
73 \code{nearPoints()} returns rows from a data frame which are near a click, hover,
74 or double-click. Alternatively, set \code{allRows = TRUE} to return all rows from
75 the input data with an additional column \code{selected_} that indicates which
76 rows of the would be selected.
77 }
78 \section{ggplot2}{
79
80 For plots created with ggplot2, it is not necessary to specify the
81 column names to \code{xvar}, \code{yvar}, \code{panelvar1}, and \code{panelvar2} as that
82 information can be automatically derived from the plot specification.
83
84 Note, however, that this will not work if you use a computed column, like
85 \verb{aes(speed/2, dist))}. Instead, we recommend that you modify the data
86 first, and then make the plot with "raw" columns in the modified data.
87 }
88
89 \section{Brushing}{
90
91 If x or y column is a factor, then it will be coerced to an integer vector.
92 If it is a character vector, then it will be coerced to a factor and then
93 integer vector. This means that the brush will be considered to cover a
94 given character/factor value when it covers the center value.
95
96 If the brush is operating in just the x or y directions (e.g., with
97 \code{brushOpts(direction = "x")}, then this function will filter out points
98 using just the x or y variable, whichever is appropriate.
99 }
100
101 \examples{
102 \dontrun{
103 # Note that in practice, these examples would need to go in reactives
104 # or observers.
105
106 # This would select all points within 5 pixels of the click
107 nearPoints(mtcars, input$plot_click)
108
109 # Select just the nearest point within 10 pixels of the click
110 nearPoints(mtcars, input$plot_click, threshold = 10, maxpoints = 1)
111
112 }
113 }
114 \seealso{
115 \code{\link[=plotOutput]{plotOutput()}} for example usage.
116 }