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

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

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

在这里输入图像描述

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


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()

在这里输入图像描述

链接地址: http://www.djcxy.com/p/34530.html

上一篇: 梳理元组的二维列表,然后用Python对它们进行排序

下一篇: 如何将标题添加到轮廓图上的颜色键?