How to add a caption to a color key on a contour chart?

How to add a caption to a color key in a lattice contour grid?

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

enter image description here

I searched the documentation and see nothing about the text or headers for the colorkey argument or in any of the other contour / level contour parameters.

+6
source share
1 answer

I found several different ways to do this and thought that I posted them for posterity:

Option 1

From the comment: How to make two small changes to the contour structure created in the grid , 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

Source: How to add a title to the legend scale using levelplot in R? thanks @ 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

+2
source

All Articles