I tried to use NetCDF file to draw a raster map in R using raster
and ncdf4
packages.
The range of my data is too large, but almost my data distributes within 0-2000. You can look at the histogram of my data:
So I want to draw a plot with the interval of 200, like seq(0, 2000, 200)
.
But when I used these intervals, the values which are larger than 2000 were recognized by R as NA
when drawing the plot. These large values are printed as transparent when drawing.
The plot using even intervals:
I tried to give large intervals to the plot, like breaks = c(seq(0, 1500, 100), 40000)
, but the legend of the plot looks ugly.
In a word, I want a plot with even interval and legend. Something like an open range, not a closed range.
The following plot is my desirable plot realized by other software. How can I resolve my problems using R?
My code is here:
library(rgdal)
library(raster)
library(ncdf4)
library(rasterVis)
library(sp)
ncname <- "output.nc"
ncdata <- nc_open(ncname)
bb <- raster(ncname)
hist(bb)
hist(bb, xlim = c(0, 2000), breaks = seq(0, 40000, 500))
plot(bb)
plot(bb, xlim = c(25, 53), asp = 1.5, breaks = c(seq(0, 1500, 100), 40000), col = topo.colors(20))
plot(bb, legend.only = FALSE, zlim = c(0, 2000), col = topo.colors(20), asp = 1.5,
legend.width = 1, legend.shrink = 1.0,
axis.args = list(at = seq(0, 2000, 100),
labels = seq(0, 2000, 100)))