Skip to content
Prev 306966 / 398506 Next

How to convert array dim names to expressions for plotting?

Dear Bert,

thanks, I was confused (of course). So the right question would have been: How to convert strings to expressions (plotmath expressions). But that I could easily find, thanks.

Cheers,

Marius

Here is the working example (showing plotmath and just-character labels):

require(grid)

tau <- c(0.25, 0.75)
alpha <- c(0.95, 0.99, 0.999)
a <- array(1:6, dim=c(2,3), dimnames=list(tau=tau, alpha=alpha))

dimnames(a)$tau[1] <- "tau==0.25" ## dimnames(a)$tau <- paste0("tau==", tau)
dimnames(a)
gl <- grid.layout(1, 2, default.units="inch", widths=c(2,2), heights=c(2,2))
## grid.show.layout(gl)
pushViewport(viewport(layout=gl))

pushViewport(viewport(layout.pos.row=1, layout.pos.col=1))
grid.rect(gp=gpar(col=NA, fill="gray80"))
grid.text(parse(text=dimnames(a)[["tau"]][1]), x=0.5, y=0.5)
upViewport()

pushViewport(viewport(layout.pos.row=1, layout.pos.col=2))
grid.rect(gp=gpar(col=NA, fill="gray50"))
grid.text(parse(text=dimnames(a)[["tau"]][2]), x=0.5, y=0.5)
upViewport()