【发布时间】:2020-10-03 18:22:38
【问题描述】:
我正在尝试使用下面的代码将图例添加到我的分类图中。
library(raster)
library(RStoolbox)
landsat5 <- stack('lt05.tif')
shp<-shapefile("to5/to.shp")
SC_rf <- superClass(landsat5, shp, responseCol = "MC_ID",
nSamples = 1000, polygonBasedCV = TRUE,
model = "rf", tuneLength = 5, kfold = 5,
mode = "classification", predType = "raw", overwrite = TRUE)
## Plots
colors <- c("yellow", "green", "deeppink", "orange", "red")
plot(SC_rf$map, col = colors, legend = TRUE, axes = FALSE, box = FALSE)
legend(1, 1, legend = levels(shp$MC_info), fill = colors , title = "Classes")
地图已创建,但出现图例错误:
'legend(1, 1, legend = levels(shp$MC_info), fill = colors, title = "Classes")': 'legend' 的长度为 0
【问题讨论】:
-
shp$data$MC_info? -
没有帮助,仍然报同样的错误
-
是的,在这两种情况下,'legend' 的长度都是 0
-
从图片来看,
shp没有名为MC_info的单元格。MC_info在shp$data中。shp$MC_info会返回任何东西吗?它的类是什么? -
shp$MC_info不再显示错误但仍不显示图例。并且 shp 有 SpatialPolygonsDataFrame 类
标签: r plot classification raster shapefile