r - 在R中创建栅格直方图

标签 r raster r-raster

我想使用以下方法创建光栅图像的值分布图,例如直方图或图形:

library(raster)
library(sp)
library(rgdal)
DEM <- raster("NR.tif")
hist(DEM)
plot(DEM)

plot() 用于验证我的数据并向我显示全绿色图像。据说是 3 中的第 1 带。 但是我看不到其他乐队? 显然,直方图中的分布并不代表图像文件中的插值。 在 ARCgis 中创建的直方图在这里 hist ,我相信它代表了真正的值(value)。

关于如何创建真实值直方图的任何建议,例如 image .

最好, 马蒂亚斯

最佳答案

你可以试试

download.file("https://www.dropbox.com/s/t279m5ojners7fl/NR.tif?dl=1", 
              tf <- tempfile(fileext = ".tif"), mode="wb")
library(raster)
library(tiff)
library(ggplot2)
library(reshape2)
DEM <- readTIFF(tf)
plot(as.raster(DEM))

enter image description here

ggplot(melt(DEM), 
       aes(value, fill=as.factor(Var3))) + 
  geom_histogram(position="dodge") 

enter image description here


或者,关于您的更新

r <- as.raster(DEM)
tab <- as.data.frame(sort(table(r)))
ggplot(subset(tab, !r %in% c("#F0F0F0", "#000000")), 
              aes(x=r, y=Freq, fill=I(r))) + 
         geom_bar(stat="identity") + 
  theme(axis.text.x = element_text(angle=90))

enter image description here

关于r - 在R中创建栅格直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37446334/

相关文章:

r - 顶部光栅背景上的空间对象图例

r - 计算多边形的坡度和坡向

r - r中使用mosaic合并多个geotiff

重新投影 SpatialPointsDataFrame 不会更改范围

r - 对数字变量进行分箱

r - 在一组中查找不在另一组中的值对

r - 使用偏移变量模拟负二项式分布

python - 名称 'netCDF4' 未定义 - RStudio 中的 python

r - 如何在矢量图上插入区域?

python-2.7 - 使用来自另一个栅格的数据填充 geotiff 中的无数据值