qaxis: Create an axis layer

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

View source: R/axes.R

Description

This function creates an axis layer which contains tick marks and labels at given locations.

Usage

1
qaxis(parent = NULL, meta = NULL, side = 1, at = NULL, labels = NULL, ...)

Arguments

parent

the parent layer (default to be NULL, which means creating an independent layer with no parents, but it can be added to a parent layer using the approach parent[i, j] <- child_layer)

meta

NULL means to use at and labels, otherwise it should be a list containing child elements xat, yat, xlabels and ylabels, and it will override the arguments at and labels; besides, another child element meta$limits must be present to set the limits of the layer

side

which side to draw the axis (following the convention of R base graphics, i.e., 1: bottom, 2: left, 3: top, 4: right); the location of tick marks and labels will automatically adjusted according side

at

the locations of tick marks

labels

the labels of the tick marks

...

other arguments passed to qlayer

Value

a layer object

Note

The vertical range of the x-axis is [0, 1], and the horizontal limit of y-axis is [0, 1].

If meta is not NULL, it is supposed to be a reference object, and an event will be attached on meta$limits so that the limits of the axis layer will sync with meta$limits dynamically.

Author(s)

Yihui Xie <http://yihui.name>

See Also

axis, qlayer

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
library(cranvas)
library(qtpaint)

s <- qscene()
r <- qlayer(s)
r[1, 1] <- qlayer(paintFun = function(layer, painter) {
    qdrawCircle(painter, runif(1000, 0, 10), runif(1000, -5, 3), r = 2)
    qdrawRect(painter, 0, -5, 10, 3)
}, limits = qrect(c(0, 10), c(-5, 3)))  # main layer
## note the vertical limits of x-axis and horizontal limits of y-axis are [0, 1]
#' x-axis
r[2, 1] <- qaxis(side = 1, at = c(0, 1, 3, 7, 8), limits = qrect(c(0, 10), c(0, 1)))
#' y-axis
r[1, 0] <- qaxis(side = 2, at = c(-4.5, -1, 0, 1.5, 2.5), limits = qrect(c(0, 1), 
    c(-5, 3)))
#' top x-axis
r[0, 1] <- qaxis(side = 3, meta = list(xat = c(1, 3, 7), xlabels = c("a", "b", "c"), 
    limits = matrix(c(0, 10, -5, 3), 2)))

fix_dimension(r, row = list(id = c(0, 2), value = c(30, 30)), column = list(id = 0, 
    value = 30))

qplotView(scene = s)

cranvas_off()

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