1

I've been trying to add a title (via main) to a map created with spplot that consists of two lines of text, but with the second line italicised. The text in each line is drawn from a variable name. I've variously tried using bquote and expression, but with no luck.

A basic example of my starting point is below, although in my actaul usage the text for a and b are drawn iteratively from a vector as part of a loop. Any suggestions as to how to keep the two lines split as per the example, but with the second line of text italicised would be much appreciated. I hope the example is clear. Thanks in advance.

require(sp)
data(meuse)
coordinates(meuse)<-~x+y

a<-"line 1"
b<-"line 2"
title<-paste(a,'\n',b,sep="")

spplot(meuse,c("ffreq"),col.regions="black",main=title)
4

1 回答 1

2
spplot(meuse, c("ffreq"), col.regions="black",
               main= expression( atop(line~1, italic(line~2) ) )  )

如果您真的想隔离 a="line 1" 和 b="line 2" 变量并“传入”,您可以使用以下形式:

spplot(meuse, c("ffreq"), col.regions="black",
             main= as.expression( bquote( atop(.(a), italic(.(b) ) ) ) ) )

我会注意到 bquote() 返回的值实际上不是一个表达式,而是一个“语言”对象。lattice 的作者 Deepayan Sarkar 认为这些不值得被视为 lattice 框架中的表达式。在基本图形和 ggplot2 中通常可以接受不使用bquoteas.expression 包装器,但在 lattice 调用中会失败。我最初(不成功)尝试:

 spplot(meuse, c("ffreq"), col.regions="black",
             main=  bquote( atop(.(a), italic(.(b) ) ) ) ) 
于 2013-05-04T02:18:35.137 回答