qmtext: Create a margin text layer

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

View source: R/axes.R

Description

This function is similar to mtext, which draws text into the margin of a plot. A slight difference is this function creates a layer which can be put anywhere in the layout. We can also create a title layer with this function.

Usage

1
2
qmtext(parent = NULL, meta = NULL, side = 1, text = "", x = 0.5, y = 0.5, cex = 1, 
    ...)

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 text directly, otherwise it can override text

side

which side to draw the text (following the convention of R base graphics); e.g. side = 3 can be used to create the title layer

text

the character string to draw; if meta is not NULL, this argument will take values from meta$xlab if side == 1, meta$ylab if side == 2, and meta$main if side == 3

x

the x coordinate

y

the y coordinate

cex

the expansion factor

...

other arguments passed to qlayer

Details

As in R base graphics, the margin means the bottom, left, top and right area of the main plot region. This function will adjust the direction of the text according to the side to which it is drawn, e.g., the left or right side will make the text vertical.

Value

a layer object

Note

The limits of the text layer is [0, 1] both horizontally and vertically by default.

Author(s)

Yihui Xie <http://yihui.name>

See Also

mtext, qlayer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
library(cranvas)
library(qtbase)
library(qtpaint)

s <- qscene()
r <- qlayer(s)  # root layer
m <- qlayer(paintFun = function(layer, painter) {
    qdrawCircle(painter, runif(1000), runif(1000), r = 2)
    qdrawRect(painter, 0, 0, 1, 1)
}, limits = qrect(matrix(c(0, 1, 0, 1), 2)))  # main layer
m1 <- qmtext(text = "x axis title!", side = 1)
m2 <- qmtext(text = "y axis title!", side = 2)
m3 <- qmtext(text = "THE MAIN TITLE", side = 3)
m4 <- qmtext(text = "text on the right margin", side = 4)
## note how to arrange these layers appropriately in the margin
r[1, 1] <- m
r[2, 1] <- m1
r[1, 0] <- m2
r[0, 1] <- m3
r[1, 2] <- m4
print(qplotView(scene = s))

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