[R] Colour Legend text, in a print color2D.matplot

Jim Lemon jim at bitwrit.com.au
Sun Nov 10 23:59:41 CET 2013


On 11/11/2013 04:57 AM, Alaios wrote:
> Hi all,
>
> I am plotting very nice looking mattrices with  plotrin...
>
> so far so good, I would like though to ask you if it would be possible to add at the bottom of the color.legend (this lovely color bar that maps colors to numbers).
> Would that be possible to do that?
>
Hi Alex,
It is not too difficult:

# first allow printing outside the plot
par(xpd=TRUE)
# get the x component of the label
# from the values passed to color.legend
# see the help page
labelx<-(xl+xr)/2
# get the y coordinate from the y value
labely<-yb-strheight("M")
# display the label
text(labelx,labely,mylabel)
# restore the clipping
par(xpd=FALSE)

Jim



More information about the R-help mailing list