我想使用以下方法创建光栅图像的值分布图,例如直方图或图形:
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))
ggplot(melt(DEM),
aes(value, fill=as.factor(Var3))) +
geom_histogram(position="dodge")
或者,关于您的更新
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))
关于r - 在R中创建栅格直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37446334/