Reputation: 41
I am plotting maps of atmospheric pollutant fields, or meteorological field, difference between such fields, often overlayed with orography. My fields are gridded.
A white line misteriously appears, sometimes two.
This seems to happen a bit randomly. I mean: same code and fields, same line; but when I change fields, or color scales, it changes position, or it disappears, or another one appears. Sometimes horizontal, sometimes vertical.
Here is my code
#!/usr/bin/env Rscript
library(rasterVis)
library(RColorBrewer)
NX <- 468
NY <- 421
hgt <- matrix(0.,NX,NY)
# read from file:
ucon <- file("hgt.dat", open="rb")
for (n in seq(1,NX)) {
hgt[n,] <- readBin(ucon, "numeric", n=NY, size=4)
}
close(ucon)
hgtbks <- c(-100,10,500,1000,1500,2000,2500,3000,3500)
hgtcols <- colorRampPalette(c("gray30","white"))(length(hgtbks)-1)
tit <- "Orography"
bkstart=50.0; bkmax=1500.; bkby=100.
bks <- seq(bkstart, bkmax, bkby)
nbks <- length(bks)
cols <- rev(colorRampPalette(brewer.pal(11,"Spectral"))(nbks-2))
cols <- c("white",cols)
legendbreaks <- seq(1,nbks)
legendlabels <- formatC(bks,digits=3)
legendlabpos <- legendbreaks
rpl <-
levelplot(hgt, margin=FALSE , col.regions= hgtcols, at= hgtbks
, main= list(label=tit, cex=1.8)
, colorkey=list(draw= TRUE, col=cols, at=legendbreaks
, labels=list(labels=legendlabels, at=legendlabpos, cex=1.2))
, xlab=NULL, ylab=NULL, scales= list(draw= FALSE))
png("whiteline.png", width=800, height=840)
plot(rpl)
graphics.off()
I would really like to upload a file with my data, but for the moment I could not find a way to do it (I don't think I can do it, not even an ASCII file). The data matrix (468x421) is too big to be explicitly included in the code, but it really is the orography file shown in the picture (elevation in meters above mean sea level).
And here is the resulting "white line" map:
Really, I think this might be a levelplot bug. It seems to happen both when hgt is a matrix and when it is a proper raster object: this doesn't seem to make a difference. Any idea?
Upvotes: 0
Views: 262
Reputation: 1
I have a feeling, that problem appears when saving plot to file. I have the same problem with white lines. When I chnged size of output file, problem dissapeared.
Part of my script:
png(picture, width=1000, height=800)
my.at=seq(0,100,by=5)
myColorkey <- list(at=my.at, space="right", labels=list(at=my.at, cex=1.5))
Mylabel <- sprintf ("%s-%s-%s Wskaźnik wilgotności gleby, warstwa 0-7 cm [%%]",Dzien,Mies,Rok)
levelplot(cm, col.regions=rev(turbo(32)), margin=FALSE, contour=TRUE, region=TRUE,
at = my.at, colorkey=myColorkey,
xlab = NULL, ylab = NULL,
main=list(label=Mylabel,side=1,line=0.75, cex=1.5))
dev.off()
When I changed line:
png(picture, width=1000, height=800)
to:
png(picture, width=1200, height=1000)
problem with white line dissapeared.
Upvotes: 0
Reputation: 41
I think I found a workaround. By setting zero padding on the 4 sides, I managed to make the whiteline disappear from a series of maps. First I defined:
zpadding <- list(layout.heights= list(top.padding=0, bottom.padding=0),
layout.widths= list(left.padding=0, right.padding=0))
then I added, among the parameters of the levelplot call:
par.settings=zpadding
As I said, I don't think this is a proper solution, but a workaround.
The problem seems related to any rescaling of the plot area.
In fact, when a rescaling is forced by, for example, having 4 or 5 digits (instead of 2 or 3) in the colorbar labels, a white line may reappear.
I hope this may point in the right direction other people, either users or developers of levelplot and related software.
Upvotes: 0