library(raster)
## Loading required package: sp
library(rasterVis)
## Loading required package: lattice
## Loading required package: latticeExtra
## Loading required package: RColorBrewer
library(rgdal)
## rgdal: version: 1.1-1, (SVN revision 572)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
## Path to GDAL shared files: C:/Users/Katsura/Documents/R/win-library/3.2/rgdal/gdal
## GDAL does not use iconv for recoding strings.
## Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
## Path to PROJ.4 shared files: C:/Users/Katsura/Documents/R/win-library/3.2/rgdal/proj
## Linking to sp version: 1.2-1
library(cluster)
library(RColorBrewer)
You can also embed plots, for example:
num_phase = 6
clarax <- clara(stackImg[], k=num_phase)
stackImg$clusters <- as.factor(clarax$clustering)
cols <-brewer.pal(num_phase, "Set2")
plot(stackImg$clusters, col = cols)
table(clarax$clustering)
##
## 1 2 3 4 5 6
## 68898 427697 200340 14199 35202 40096