我想增加一個圖標中的圖例的標題保存到變量中。我已經使用here的代碼將一個colorkey圖例標題添加到保存到變量的等級圖圖中。在levelplot上增加colorkey標題的字體大小
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
但我想增加圖例標題的字體大小。我試圖在vjust
參數後指定gp=gpar(fontsize=14)
和gp=gpar(cex=9)
,但字體大小不變。不完全確定gp
參數是如何工作的,我假定它跟在grid.text
之後,並且從gpar
開始,但它似乎不起作用?在your Theme 的MyTheme $字號$文本< -10 或任何大小