Reputation: 27
I am trying to increase the title for a legend in a levelplot graph saved to a variable. I've used code from here to add a colorkey legend title to a levelplot graph that is saved to a variable.
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
But I would like to increase the font size of the legend title. I tried specifying gp=gpar(fontsize=14)
and gp=gpar(cex=9)
after the vjust
argument, but the font size doesn't change. Not entirely sure how the gp
argument works, I assumed it follows grid.text
and takes from gpar
but it doesn't seem to work?
Upvotes: 0
Views: 4249
Reputation: 6406
You can change the title font size using cex
, for example:
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))
Upvotes: 1