Marius Hofert
2010-Nov-26 08:30 UTC
[R] How to use expression(italic()) in a "vectorized" way (within a function)?
Dear expeRts, I would like to use expression() for creating labels in a splom, as shown in the first minimal example below. Is there any way I can simplify having to write "expression(italic(...))" several times? The second example is what I tried so far, but I can't manage to get italic() to work. Moreover, it still seems bulky... Cheers, Marius ## minimal example (working but bulky) U <- matrix(runif(900),ncol=3) lattice::splom(~U[,1:3],varnames = c(expression(italic(U[1])),expression(italic(U[2])),expression(italic(U[3])))) ## also bulky (and does not incorporate italic()) f <- function(x){ do.call(expression, lapply(1:3, function(j) substitute(x[y], list(x = as.name(x), y = 0+j)))) } lattice::splom(~U[,1:3],varnames = f("U"))
Gabor Grothendieck
2010-Nov-26 15:24 UTC
[R] How to use expression(italic()) in a "vectorized" way (within a function)?
On Fri, Nov 26, 2010 at 3:30 AM, Marius Hofert <m_hofert at web.de> wrote:> Dear expeRts, > > I would like to use expression() for creating labels in a splom, as shown in the > first minimal example below. Is there any way I can simplify having to write > "expression(italic(...))" several times? > The second example is what I tried so far, but I can't manage to get italic() to > work. Moreover, it still seems bulky... > > Cheers, > > Marius > > ## minimal example (working but bulky) > U <- matrix(runif(900),ncol=3) > lattice::splom(~U[,1:3],varnames = c(expression(italic(U[1])),expression(italic(U[2])),expression(italic(U[3])))) > > ## also bulky (and does not incorporate italic()) > f <- function(x){ > ? ?do.call(expression, lapply(1:3, function(j) substitute(x[y], list(x = as.name(x), y = 0+j)))) > } > lattice::splom(~U[,1:3],varnames = f("U")) >bquote can be used to shorten it slightly: L <- lapply(1:3, function(i) bquote(italic(U[.(i+0)]))) splom(~U[,1:3], varnames = as.expression(L)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Maybe Matching Threads
- splom, plotmath: how to add three lines of information with alignment?
- How to put given values in lower triangle of splom-plot?
- Lattice: How to color the data points in splom() according to the panel they are plotted?
- Quiz: Who finds the nicest form of X_1^\prime?
- Adding axis lines to splom plots