cranvas (version 0.8.5)

qmtext: Create a margin text layer

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

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

Value

a layer object

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.

See Also

mtext, qlayer

Examples

Run this code
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))

Run the code above in your browser using DataLab