2

I need make meteorological maps with package lattice. But i found a problem in comand levelplot(). I can make maps with the comand using a regular label. E.g: Correlation maps with label 0, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35 0.4... In this example the label skip five by five (Fig.1).

h1<- levelplot(var~x*y,data = idw.msk.dfr,contour=F,at=seq(0,0.5,0.05),
           par.settings = paleta1,main = "correlation map",
           xlab = NULL, ylab = NULL, ylim = c(-60,15), xlim = c(-90,-30))

Figure 1:

Figure 1

But, i need make maps with non-regular values. E.g: 0, 0.1, 0.15, 0.2, 0.22, 0.25, 0.40... When put this values in code, i get this result (Fig.2):

h1<- levelplot(var~x*y,data = idw.msk.dfr,contour=F,at=c(0,0.1,0.15,0.2,0.22,0.25,0.4,0.5),
           par.settings = paleta1,main = "correlation map",
           xlab = NULL, ylab = NULL, ylim = c(-60,15), xlim = c(-90,-30))

Figure 2 Figure 2

Note that the label of map is very strange and inrregular.

So. How do i solve this problem? I will apreciate your help.

Chandresh Khambhayata
  • 1,748
  • 2
  • 31
  • 60

1 Answers1

0

You need to specify a custom colorkey. Add colorkey to the levelplot function.

x <- seq(pi/4, 5 * pi, length = 100)
y <- seq(pi/4, 5 * pi, length = 100)
r <- as.vector(sqrt(outer(x^2, y^2, "+")))
grid <- expand.grid(x=x, y=y)
grid$z <- cos(r^2) * exp(-r/(pi^3))

breaks <- c(0, 0.1, 0.15, 0.2, 0.22, 0.25, 0.4, 0.5)

levelplot(z~x*y, grid, at=breaks)

enter image description here

myColorkey=list(at=breaks, labels=list(at=breaks, labels=breaks))

levelplot(z~x*y, grid, colorkey=myColorkey)

enter image description here

To have the same size for the intervals change the at argument:

ats=seq(0, 0.5, by=0.07)
myColorkey=list(at=ats, labels=list(at=ats, labels=breaks))
levelplot(z~x*y, grid, colorkey=myColorkey)

enter image description here

Christopher Stephan
  • 1,081
  • 16
  • 33