我正在尝试在保存到变量的levelplot图中增加图例的标题。我使用here中的代码将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
但我想增加图例标题的字体大小。我尝试在gp=gpar(fontsize=14)
参数后指定gp=gpar(cex=9)
和vjust
,但字体大小没有变化。不完全确定gp
参数是如何工作的,我假设它遵循grid.text
并从gpar
开始,但它似乎不起作用?
答案 0 :(得分:1)
MyTheme的$ $字号文字&lt; -10 或者你想要的任何尺寸
答案 1 :(得分:0)
您可以使用cex
更改标题字体大小,例如:
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(label='b',side=1,line=0.5, cex=10))