简体   繁体   中英

Plot discrete Raster data in R

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)

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 重分类 DAM 的绘图

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)

重分类地块

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM