Mikhail Titov
2011-Aug-12 18:34 UTC
[R] Any alternatives to draw.colorkey from lattice package?
Hello! I?d like to have a continuous color bar on my lattice xyplot with colors lets say from topo.colors such that it has ticks & labels at few specific points only. Right now I use do.breaks & level.colors with somewhat large number of steps. The problem is that color change point doesn?t necessary correspond to the value I?d like to label. Since I have many color steps and I don?t need high precision I generate labels like this labels <- ifelse( sapply(at,function(x) any(abs(att-x)<.03)) , sprintf("depth= %s ft", at), "") , where `att` has mine points of interest on color scale bar and `at` corresponds to color change points used with level.colors . It is a bit inconvenient as I have to adjust threshold `.03`, number of color steps so that it labels only adjacent color change point with my labels. Q: Are there any ready to use functions that would generate some kind of GRaphical OBject with continuous color scale bar/key with custom at/labels such that it would work with `legend` argument of xyplot from lattice? Mikhail
Jim Lemon
2011-Aug-13 09:59 UTC
[R] Any alternatives to draw.colorkey from lattice package?
On 08/13/2011 04:34 AM, Mikhail Titov wrote:> Hello! > > I?d like to have a continuous color bar on my lattice xyplot with colors lets say from topo.colors such that it has ticks& labels at few specific points only. > > Right now I use do.breaks& level.colors with somewhat large number of steps. The problem is that color change point doesn?t necessary correspond to the value I?d like to label. Since I have many color steps and I don?t need high precision I generate labels like this > > labels<- ifelse( sapply(at,function(x) any(abs(att-x)<.03)) , sprintf("depth= %s ft", at), "") > > , where `att` has mine points of interest on color scale bar and `at` corresponds to color change points used with level.colors . It is a bit inconvenient as I have to adjust threshold `.03`, number of color steps so that it labels only adjacent color change point with my labels. > > Q: Are there any ready to use functions that would generate some kind of GRaphical OBject with continuous color scale bar/key with custom at/labels such that it would work with `legend` argument of xyplot from lattice? >Hi Mikhail, I think that color.legend in the plotrix package will do what you are asking, but it is in base graphics, and may not work with lattice. Jim