qscatter

0th

Percentile

Draw a scatter plot

This function creates a scatter plot with two numeric variables. It supports colors and sizes generated by qdata. When the sizes are not the same, a scatter plot becomes what is called the ``bubble chart''.

Usage
qscatter(x, y, data, edges = NULL, main = "", xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, asp = 1, alpha = 1, unibrushcolor = TRUE)
Arguments
x
the name of the x variable
y
the name of the y variable (if missing, x will be plotted against its indices, i.e., y will become x and x will be indices)
edges
matrix of two columns to indicate which lines to connect
asp
aspect ratio (ratio of the physical height of a plot to its width; unlike other R graphics systems, this will not affect the ranges of axes)
data
a mutaframe created by qdata
main
the main title
xlim
a numeric vector of length 2 (like c(x0, x1)) for x-axis limits; it will be calculated from the data limits if not specified (NULL). Note when x0 > x1, the axis direction will be reversed (i.e. from larger values to small values)
ylim
y-axis limits; similar to xlim
xlab
x-axis title
ylab
y-axis title
Details

All the common interactions like brushing and deleting are documented in common_key_press.

In the identify mode, the plot will show the row id(s) of the identified point(s) as well as x and y values.

Arrow keys are used in scatter plots for interactions: without the Shift key, Up and Down will increase/decrease the sizes of points; with the Shift key being pressed, Up, Down, Left and Right will move the (background of) plot to the corresponding direction.

Mouse wheel is used to zoom in and zoom out the plot. Together with keyboard interactions, this will enable us to see details in data.

Value

A scatter plot

Note

Using more than one color (including border colors) can lead to serious speed issues; this plot is fastest when we only use a single color and a single size. As the number of unique colors increases, the plotting can be slower based on a same dataset. Using more than one size is also slower than using a single size for all points; the internal painting functions are different for the two cases (qdrawCircle for the former, and qdrawGlyph for the latter).

Aliases
  • qscatter
Examples
library(cranvas)

### (1) tennis data
qtennis <- qdata(tennis)

qscatter(first.serve.pct, second.serve.pts, data = qtennis, xlab = "First Serve %", 
    ylab = "Second Serve Points")
qscatter(return.games, first.serves, data = qtennis)

### (2) flea: color by categorical variable, and linking
data(flea, package = "tourr")
qflea <- qdata(flea, color = species)  # use species to create colors

qscatter(tars1, aede1, data = qflea)
qscatter(tars2, head, data = qflea)

qscatter(tars1, tars2, data = qflea, asp = 0.7)  # aspect ratio

qscatter(tars1, tars2, data = qflea, unibrushcolor = FALSE)  # brush color

## link qflea to itself using species
id <- link_cat(qflea, "species")

## remove linking
remove_link(qflea, id)

## a bubble chart
qflea2 <- qdata(flea, color = NA, border = species, size = tars1)
qscatter(tars1, tars2, data = qflea2)

### (3) NRC rankings

qnrc <- qdata(nrcstat, color = RegCode)

qscatter(RRankings5th, RRankings95th, data = qnrc)

qscatter(SRankings5th, SRankings95th, data = qnrc)

qscatter(SRankings5th, SRankings95th, data = qnrc, unibrushcolor = FALSE)

### (4) secrets in the pollen data
library(animation)
data(pollen, package = "animation")
head(pollen)
qpollen <- qdata(pollen, size = 2)
qscatter(RIDGE, CRACK, data = qpollen)
## try zooming into the center or press +/-

### (5) pressure test; run with care!
n <- 1e+06  # a million still works (at least for me)
df <- qdata(data.frame(x = rnorm(n), y = rnorm(n), z = gl(4, n/4)), color = z)
qscatter(x, y, data = df)

cranvas_off()
Documentation reproduced from package cranvas, version 0.8.5, License: GPL

Community examples

Looks like there are no examples yet.