Create a mutaframe from data with attributes for interaction

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).

qdata(data, color = "gray15", border = color, size = 4, brushed = FALSE, visible = TRUE, ...)
a data frame (it will be coerced to a data frame if it is not)
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 data (must be either a factor or a numeric variable), or an R expression to calculate colors; color is used to fill the interior of graphical elements
colors for the border of graphical elements (e.g. rectangles); NA means to suppress the border
sizes of rows; possible values are similar to color, but when using a variable to generate sizes, it must be a numeric variable
a logical vector indicating which rows are brushed (default all FALSE)
a logical vector indicating which rows are visible (default all TRUE)

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

See Also

mutaframe, brush

  • qdata
## 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)

Documentation reproduced from package cranvas, version 0.8.5, License: GPL

Community examples

Looks like there are no examples yet.