Description Usage Arguments Details Value Author(s) See Also Examples
This function will first check if the names of some pre-defined row
attributes (e.g. .color
, .brushed
) exist in the column names of
the data (will issue an error if they do); then append these columns to the
original data to create an augmented data as a
mutaframe
; in the end add some attributes to the
mutaframe for the purpose of interaction (mainly the brush
object and the linking specification).
1 2 |
data |
a data frame (it will be coerced to a data frame if it is not) |
color |
colors of graphical elements (default dark gray) corresponding
to rows of data; it can be a vector of valid R colors, or a name of
variable in |
border |
colors for the border of graphical elements (e.g. rectangles);
|
size |
sizes of rows; possible values are similar to |
brushed |
a logical vector indicating which rows are brushed (default
all |
visible |
a logical vector indicating which rows are visible (default
all |
When the three arguments color
, border
and size
take
values as variable names in data
, default palettes will be used to
generate colors and sizes. The sequential color gradient palette
(seq_gradient_pal
) will be applied to continuous
variables, and the hue palette (hue_pal
) will be
applied to categorical variables. The area palette
(area_pal
) is used to create a size vector when the
size variable is continuous. An attribute attr(data, 'Scales')
is
attached to the returned mutaframe, which will help specific plots to
generate legends. This attribute is of the form list(color =
list(title, variable, palette))
. Whenever any component is changed, the
corresponding aesthetics will be updated automatically; for example, if we
change the palette function for color
, the colors data$.color
will be updated using the new palette. See color_pal<-
for a
list of functions on how to modify scales information.
a mutaframe with attributes for interaction
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 | library(cranvas)
str(tennis)
## more Aces, closer to red; less, blue; higher speed, larger points
qtennis <- qdata(tennis, color = aces, size = serve.speed)
qhist(aces, data = qtennis, main = "Number of Aces")
ls.str(attr(qtennis, "Scales")) # the scales information
selected(qtennis)[1:10] <- TRUE # brush the first 10 cases
b <- brush(qtennis) # the brush object
b$style # style the brush rectangle
b$style$color <- "brown" # a brown brush
b$color # color of brushed elements
b$color <- "cyan" # brushed elements become cyan
attr(qtennis, "Shadow") # should be NULL, since no misssing values here
## we can also use the default dark gray
qtennis <- qdata(tennis)
qhist(double.faults, data = qtennis)
cranvas_off()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.