0

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:

1

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?

  • 1
    Perhaps it would be better if you could share a piece of your data so that others can use it and help you more efficiently. – Anoushiravan R Mar 29 '21 at 11:17
  • @AnoushiravanR , I could not upload my binary data file (I don't think I can, not even an ASCII file). The data matrix is 468x421, it is too big to be explicitly included in the code. It contains floating point numbers in the range -100:5000 (elevation in meters above mean sea level). AND I don't know why the new image that I uploaded today could not be embedded in the text – Francesco Uboldi Apr 08 '21 at 12:27
  • I don't have much experience in this area, but it is essential to share a piece of your data if contributors are to help you. Otherwise it won't attract any response. Just try `dput(head(data))` and copy the output in your question, that way you will have more chances on getting relevant results. – Anoushiravan R Jun 30 '21 at 17:38
  • I had the same problem with ggplot2 and geom_tile. I succeeded, in this case, following the suggestion "setting a small margin" here: https://stackoverflow.com/questions/36334363/white-lines-on-heat-map-made-by-ggplot2 like this: "myplot <- myplot + theme(plot.margin=unit(c(0.1,0.1,0.1,0.1),"cm")" I don't know if the levelplot problem (bug) is similar and if it can have a similar solution. AGAIN I CANNOT INSERT MY DATA MATRIX IN THE QUESTION: 468x421 IS TOO BIG – Francesco Uboldi Jul 02 '21 at 15:40
  • I'm so sorry, I wish I could help. I suggest you edit your question again so it will appear on the home page of the site and it may attract new responses. – Anoushiravan R Jul 02 '21 at 17:16
  • OK, no problem. I case I am able to reproduce the error with a smaller dataset (smaller enough I mean), I will post the example with the data. I suspect that this problem arises with large dataset only, though. – Francesco Uboldi Jul 03 '21 at 10:37

1 Answers1

0

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.