0

I am able to plot but not satisfying results can be seen. It's because most of my value are within a close range seen in frequency plot. I don't know how to plot with such discrete data Data.

How can I modify the plot into a smooth map with variation in data can be seen ?

How do I code so that the legend bar starts from zero and skip negative values ?

> library(raster)
> DAM <- raster ("Data.tif")
> plot(DAM, 
+      breaks = c(0,  1e+15, 0.647103e+16, 1e+16, 1.647103e+16, 2e+16, 2.6e+16, 5e+16,8e+17, 9e+17,10e+17), col = rev(heat.colors(8, alpha = 1)))
> plot(DAM)
> summary(DAM)
                layer
Min.    -3.686638e+18
1st Qu.  2.279737e+15
Median   4.811684e+15
3rd Qu.  6.985325e+15
Max.     1.647103e+17
NA's     9.868000e+04
> breaks <- c(-3.686638e+18, -4e+17, 1,  -4e+17, 0, 2,  0,9.868000e+04,NA, 9.868000e+04,2.3e+15,4, 2.3e+15,3e+15,5, 3e+15,4e+15,6, 4e+15,4e+15,7, 4e+15,5e+15,8,6e+15,7e+15,9,  1e+16,5e+16, 10, 6e+16,1.7e+17,11)
> DAM_Matrix<- matrix(breaks, ncol=3, byrow=TRUE)
> p <-reclassify(DAM,DAM_Matrix)
> p
> plot(p)
class      : RasterLayer 
dimensions : 392, 369, 144648  (nrow, ncol, ncell)
resolution : 0.1000061, 0.09999847  (x, y)
extent     : 60.51468, 97.41693, -0.7013588, 38.49804  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
source     : memory
names      : layer 
values     : -3.686638e+18, 5.720893e+16  (min, max)

enter image description here enter image description here enter image description here Plot for reclassified DAM

Dipu
  • 123
  • 2
  • 14
  • 1
    Can you provide an example of your data ? To do it, please read: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – dc37 Jan 13 '20 at 21:27
  • or at least the output of `summary(DAM)` ? – Ben Bolker Jan 13 '20 at 21:46
  • It's done, please check – Dipu Jan 14 '20 at 07:56
  • Your data is not discrete - you can use e.g. `reclassify` to put your variable into bins, which would make it discrete. – Val Jan 14 '20 at 09:00
  • The first plot I tried with bins only. I am unable to make suitable bins...The data variation is so high (NA's, negative, positive. See the frequency plot and summary stats. – Dipu Jan 14 '20 at 09:11

1 Answers1

2

Reclassify did the job Thanx @Val for suggestion. Hope this helps others. Cheers !!!

> x <- reclassify(p, cbind(-Inf, 0, NA), right=FALSE)
> summary(x)
               layer
Min.    1.000000e+00
1st Qu. 4.000000e+00
Median  8.000000e+00
3rd Qu. 5.604096e+15
Max.    5.720893e+16
NA's    9.868100e+04
> spplot(x)

Reclassified Plot

F1Krazy
  • 146
  • 1
  • 4
  • 14
Dipu
  • 123
  • 2
  • 14