[R] how to display Greek characters in lattice plot (in the labels inside the panels)

Ranjan Maitra maitra at iastate.edu
Tue Aug 9 15:29:02 CEST 2011


Sorry. I forgot to paste 3 lines over: here is the corrected
reproducible code. 

Apologies again, and many thanks,
Ranjan

Dear friends,

I would like to know how to use Greek (and plotmath characters) in
lattice plots. Here is an example which works: but I would like to
replace "s_v" with expression(hat(sigma))_v.  

Finally, is there a way to get the BIC, ICL, etc in the same panel such
that we can have this text on its side?

Please feel free to ask me if I have not been clear or if you have
further questions or clarifications.

Many thanks again for any suggestions you are able to give!

Best wishes,
Ranjan

--- example code follows --

sigmaests <- matrix(runif(250 * 7), ncol = 7)
sigmaests <- as.data.frame(sigmaests)
names(sigmaests) <- c("BIC", "ICL", "s_v", "Q_v", "sig-p", "sig-q")



names(sigmaests) <- c("BIC", "ICL", "s_v", "Q_v", "sig-p", "sig-q")

z <- cbind(rep(c("BIC", "ICL", "s_v","Q_v", "gof-q"),
               each = 250),rep(c(5, 10, 20, 30, 50), each = 50))


# rep(rep(c(5.12, 2.66, 0.89, 0.53, 0.38), each = 50),9)) 

z <- as.data.frame(z)
z <- cbind(z, (c(sigmaests$BIC, sigmaests$ICL, sigmaests$"s_v",
                sigmaests$"Q_v", sigmaests$"sig-q")))

names(z) <- c("Method", "sigma", "Error")

z$sigma <- factor(z$sigma, c("5", "10", "20", "30", "50"))

library(lattice)

par(mar = c(3, 3, 1, 1))

sigma <- as.numeric(levels(z$sigma))
sigmaExprList <- lapply(sigma, function(s) bquote(sigma == .(s)))
sigmaExpr <- as.expression(sigmaExprList)
bwplot(Error~Method | sigma, data = z[z[,"Method"] != "gof-q",],
       horiz = F, xlab = "Method", ylab = "Relative Absolute Error",
       strip = function(which.given, which.panel, var.name,
                        strip.levels = FALSE,
                        strip.names = TRUE, ...) {
       	 strip.default(which.given, which.panel,
       	               var.name = sigmaExpr[which.panel],
                       strip.levels = FALSE,
                       strip.names = TRUE, ...)
       },
       layout = c(5,1),  col = "red")



More information about the R-help mailing list