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.
qmtext(parent = NULL, meta = NULL, side = 1, text = "", x = 0.5, y = 0.5, cex = 1, ...)
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
)NULL
means to use text
directly,
otherwise it can override text
side = 3
can be used to create
the title layermeta
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
qlayer
mtext
, qlayer
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