qhist: Draw a histogram or a spine plot

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/qhist.R

Description

Draw an interactive histogram or spine plot based on a continuous variable, optionally split by a categorical variable. It supports some common keyboard interactions (see common_key_press) as well as other interactions specific to histograms and spine plots.

Usage

1
2
3
4
5
qhist(x, data, bins = 30, binwidth = NULL, breaks = NULL, ybreaks = NULL, freq = TRUE, 
    main = "", horizontal = FALSE, spine = FALSE, xlim = NULL, ylim = NULL, xlab = NULL, 
    ylab = NULL)

qspine(x, data, ...)

Arguments

x

the name of the numeric variable to be used to draw the histogram or spine plot

bins

the desired number of bins, default=30, overridden by binwidth if provided

binwidth

the bin width (range(x) / bins by default)

breaks

sets break points, mostly for use with the tour

ybreaks

sets vertical axis, mostly for use with the tour

freq

draw the frequencies (TRUE) or densities (FALSE) (only applies to histogram)

spine

if TRUE, draw a spine plot (bar widths proportional to counts instead of being equal)

...

arguments passed to qhist

data

a mutaframe created by qdata

main

the main title

horizontal

TRUE to draw a horizontal plot or FALSE (vertical)

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

The splitting variable is usually specified in qdata as the color or border argument; if it is present, each bar in the plot will be split into categories.

Arrow keys can be used to change the binwidth as well as the breakpoints in the plot. Up and Down can increase and decrease the binwidth respectively; Left and Right can move the breakpoints of the bins to the left (smaller) or right (larger). Mouse wheel helps zoom in/out of the plot.

In the identify mode, the breakpoints of the bin(s) as well as counts and proportion of cases in the bin(s) are shown as text labels in the plot.

The function qspine is a short-hand version of qhist(..., spine = TRUE).

Value

A histogram or a spine plot

Author(s)

Yihui Xie <http://yihui.name>

See Also

Other plots: qbar; qboxplot; qdensity; qmval; qparallel; qtime

Examples

 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
37
38
39
library(cranvas)

#### (1) split histogram by species, and categorical linking
data(flea, package = "tourr")
qflea <- qdata(flea, color = species)

qhist(tars1, data = qflea)
## Use the up/down arrows to change binwidth, or the vertical bars on screen
## Right/left arrows change minimum bin (anchor) value
qhist(tars2, data = qflea, freq = FALSE, main = "density of tars2")
qhist(aede1, data = qflea, ylim = c(0, 10), main = "fix y-axis limits")
qhist(head, data = qflea, horizontal = TRUE)
qspine(aede2, data = qflea)
qparallel(~., data = qflea)  # all variables

id <- link_cat(qflea, "species")  # linking by categorical variable
## now brush one bar, all fleas of the same species will be brushed


## remove linking
remove_link(qflea, id)


#### (2) tennis data: without a splitting variable

qtennis <- qdata(tennis, color = "white", border = "black")

qhist(first.serve.pct, data = qtennis)
qbar(matches, data = qtennis)
qspine(matches, data = qtennis)

qhist(first.serve.pct, data = qtennis, horizontal = TRUE)

qhist(serve.speed, data = qtennis)
qhist(serve.speed, data = qtennis, freq = FALSE)  # density

#### see help(wages) for yet another example

cranvas_off()

ggobi/cranvas documentation built on May 17, 2019, 3:10 a.m.