Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a title to the color key on a contourplot?

Tags:

r

lattice

How does one add a title to the color key in a lattice contourplot?

library(lattice)
contourplot(volcano, region=T, main='title')

enter image description here

I've searched the documentation and don't see anything about text or titles for the colorkey argument or in any of the other contourplot/levelplot options.

like image 214
Minnow Avatar asked Jun 02 '16 18:06

Minnow


1 Answers

Found a few different ways to do this and thought I'd post them for posterity:

Option 1

Sourced from a comment: How to make two small changes to a contourplot produced in lattice thanks to @rcs.

contourplot(volcano, region=T, main='title', subtitle='sub',
    legend=list(top=list(fun=grid::textGrob("Volcanoes", y=0, x=1.09))))

Option 2

Sourced from: How to add a title to legend scale using levelplot in R? thanks to @user20650.

contourplot(volcano, region=T,main='title') 
trellis.focus("legend", side="right", clipp.off=TRUE, highlight=FALSE)
grid.text('Volcanoes', 0.5, 1.07, hjust=0.5, vjust=1)
trellis.unfocus()

enter image description here

like image 161
Minnow Avatar answered Nov 15 '22 06:11

Minnow