Description Usage Arguments Details Value Author(s) See Also Examples
The brush object in cranvas is essentially an environment, and we can manipulate objects in this environment.
1 2 3 |
data |
the mutaframe created by |
attr |
the name of the brush attribute (a character scalar), e.g.
|
value |
the value of the brush attribute |
The list of attributes in the brush (they can be accessed by the $
method):
a list containing color
, linewidth
and
linetype
defining the style of the brush (rectangle) – not to be
confused with the color of the brushed elements
the color and size of the brushed elements
the brush mode: can be 'none'
(default), 'and'
,
'or'
, 'xor'
, 'not'
or 'complement'
; see
mode_selection
for details
logical: TRUE
(turn on the identify mode) or
FALSE
(the brush mode)
a function to be used to generate the labels (based on the identified data) to show in the identify mode; the default function just prints the identified data as a character string
the color for the label in the identify mode
the size of brush history, i.e. how many brushing operations to be recorded; default to be 30
the list of indices of the brushed elements; we can go back and forth in the brush history according to this list
the current index of the brush history
persistent (TRUE
) or transient (FALSE
)
brushing; in the persistent brushing mode, the attributes of the brushed
elements will be changed permanently
a color vector to store the colors of persistently brushed elements
the persistent brushing history (a list of indices of the brushed elements)
is the mouse used to brush graphical elements
((FALSE
)) or select elements only (TRUE
); the subtle difference
here is whether the brush should stay on the plot or not when the mouse is
released
when select.only == TRUE
, zoom with selection or not
whether to draw the brush (when the mouse is released and
select.only
is TRUE
, then draw.brush
will be
FALSE
so the brush will go away)
the cursor type (an
integer; see set_cursor
)
The function brush
returns the brush object or the
attribute of the brush; note the brush object can be further manipulated
with other methods – see examples below.
Yihui Xie <http://yihui.name>
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 | library(cranvas)
qiris <- qdata(head(iris)) # create a mutaframe
brush(qiris) # the brush object (a reference object)
brush(qiris, "color")
brush(qiris, "color") <- "green" # set brush color to green
## attach events on the brush
b <- brush(qiris)
# idx is the index of the event; it can be used to stop the listening
idx <- b$colorChanged$connect(function() {
message("the color of brushed elements was changed to ", b$color)
})
b$color <- "brown"
b$color <- "gold"
b$colorChanged$disconnect(idx) # disconnect the event
b$style$color <- "red" # change the color of the brush itself to red
b$style$linewidth <- 3 # the border width to 3
b$mode <- "or" # brush mode to OR
b$history.size <- 50 # increase history size to 50
b$cursor <- 3L # cursor type to WaitCursor
b$identify <- TRUE # turn on identify mode
b$identify <- FALSE # turn off; i.e. in brushing mode now
b$persistent <- TRUE # turn on persistent brushing
## redefine label generating function: show row names in the identify mode
b$label.gen <- function(x) {
paste(rownames(x), collapse = ", ")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.