Skip to content
Back to formatted view

Raw Message

Message-ID: <48C12F9C.7060003@stats.uwo.ca>
Date: 2008-09-05T13:09:48Z
From: Duncan Murdoch
Subject: how to draw the legend about color from 3d picture
In-Reply-To: <81385cc7-6891-4b92-afa5-6bfe4c78a68d@b2g2000prf.googlegroups.com>

On 9/5/2008 8:06 AM, yk wrote:
> I have drawed a picture with persp, it's 3d map with different color,
> indicate different altitude. In gnuplot, the corresponding command
> 'splot' will generate a picture beside to indicate the relationship
> between color and altitude. But in R, how to draw it? I have read the
> manual of legend, but they are all about how to draw a legend with
> colored text, not a continuous varing color with corresponding number.

I don't think there's an automatic way to do this (though probably some 
package provides one).

If you want to write your own, take a look at example(filled.contour). 
The legend it draws is done by this code:

     plot.new()
     plot.window(xlim = c(0, 1), ylim = range(levels), xaxs = "i",
         yaxs = "i")
     rect(0, levels[-length(levels)], 1, levels[-1], col = col)
     if (missing(key.axes)) {
         if (axes)
             axis(4)
     }
     else key.axes
     box()

(but it has done a lot of setup using layout() and par() before this).

Duncan Murdoch