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

David Winsemius dwinsemius at comcast.net
Tue Aug 9 15:54:29 CEST 2011


On Aug 9, 2011, at 9:29 AM, Ranjan Maitra wrote:

> 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)) Doesn't seem like a good idea to mix  
> base and lattice graphics

Use scales with expression vector and rot=90 ... assuming the  
ambiguous phrase "text on its side" means rotated 90 degrees:

bwplot(Error~Method | sigma, data = z[z[,"Method"] != "gof-q",],
        scales=list( x =list(
           labels = expression(BIC, ICL, Q_v, hat(sigma)*"_v"),
            rot = 90 )       ),
        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")


>
> 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")
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list