0

enter image description here

I would like to define color breaks, position of colorbar all within the colorkey argument. I have tried using the following:

library(raster)
library(rasterVis)

p.at =seq( 1.160766  ,3.554995 ,length.out = 17)# I have 16 colors breaks
p.at=round(p.at,digits = 1)# min and max of all datasets
#Moreover, if you want to define where the labels are located define the components of colorkey:
Labels<-list(at=p.at)
Colorkey <- list(at=at,labels=Labels)## where the colors change   ## where to print labels
themes <- rasterTheme(region=brewer.pal(11,'RdYlBu'))

s <- stack(Precip_JJA,Precip_JJAsim)# two datasets
#x.scale=list(cex=1, alternating=1, col='black')
#y.scale=list(cex=1, alternating=1, col='black')
#scales=list(x=x.scale, y=y.scale)
Precip_plot<-levelplot(s, layout=c(2, 1), index.cond=list(c(1, 2)),par.settings=themes,scales=list(x=list(draw=FALSE)),  
                    margin=FALSE,xlab=NULL,par.strip.text=list(cex=0),
                    colorkey = list(space = "bottom",labels = list(cex=1,at = p.at),lab = p.at))

Precip_plot

Problem: the labels do not align exactly with the color breaks. See image above. Is there something wrong with my code?

Many thanks, aez.

www
  • 38,575
  • 12
  • 48
  • 84
code123
  • 2,082
  • 4
  • 30
  • 53
  • Read this FAQ: http://oscarperpinan.github.io/rastervis/FAQ.html#sec-1 – Oscar Perpiñán Feb 27 '15 at 13:00
  • 1
    @OscarPerpiñán thanks. I did find the solution on that page. That is my refernce chart. I solved the problem with this:myat =seq(floor(0.170084) ,ceiling(181.8862),length.out=20) myat=round(myat,digits = 0)# min and max of all datasets #themes <- rasterTheme(region=rev(brewer.pal(11,'RdYlBu'))) myColorkey <- list(at=myat,space = "right",labels=list(cex=1,at=myat)) – code123 Feb 27 '15 at 23:11
  • @OscarPerpiñán, please help with this: http://stackoverflow.com/questions/28753126/visualize-negative-poitive-data-using-levelplot-in-r – code123 Feb 27 '15 at 23:14

0 Answers0