我正在尝试在保存到变量的 levelplot 图中增加图例的标题。我已使用此处的代码将颜色键图例标题添加到保存到变量的 levelplot 图中。
library(lattice)
library(grid)
# Amend key function
# Hopefully a nicer way to do this!
mykey <- draw.colorkey
body(mykey)[28:30] <- list(
quote(
if(!is.null(key$title)){
key.gf <- placeGrob(key.gf,
textGrob(key$title,hjust=key$hjust, vjust=key$vjust, gp=key$gp),
row=key$row, col=key$column)
}),
body(mykey)[[28]],
body(mykey)[[29]])
# Assign to namespace: https://stackoverflow.com/questions/6254744/override-a-function-that-is-imported-in-a-namespace
unlockBinding("draw.colorkey", as.environment("package:lattice"))
assign("draw.colorkey", mykey, "package:lattice")
unlockBinding("draw.colorkey", getNamespace("lattice"))
assign("draw.colorkey", mykey, getNamespace("lattice"))
# Draw plot
x = 1:10
y = rep(x,rep(10,10))
x = rep(x,rep(10))
z = x+y
p <- levelplot(z~x*y,
colorkey=list(labels=list(cex=1, font=2, col="brown"),
height=1, width=1.4,
title=expression(m^3/m^3), row=3, column=1, vjust=2),
main=list('b',side=1,line=0.5))
p
但我想增加图例标题的字体大小。我尝试在参数之后指定gp=gpar(fontsize=14)
and ,但字体大小没有改变。不完全确定这个论点是如何工作的,我假设它遵循并从中获取,但它似乎不起作用?gp=gpar(cex=9)
vjust
gp
grid.text
gpar