1
I did a cluster analysis k-Means fictitious. I want to create a caption (cluster1, cluster2 and cluster3), which is represented by the variable "kmeans" (formed clusters). I do not know if it would be possible to insert a scale. If possible, how to do?
library(sp)
library(rgdal)
library(RColorBrewer)
map<-readOGR("C:\\Users\\EU\\Desktop\\file","UFEBRASIL")
head(map@data)
ID CD_GEOCODU NM_ESTADO NM_REGIAO
0 1 11 RONDÔNIA NORTE
1 2 12 ACRE NORTE
2 3 13 AMAZONAS NORTE
3 4 14 RORAIMA NORTE
4 5 15 PARÃ NORTE
5 6 16 AMAPÃ NORTE`
map@data$newvar1<-runif(27,20,100)
map@data$newvar2<-runif(27,20,100)
map@data$newvar3<-runif(27,20,100)
map@data$newvar4<-runif(27,20,100)
map@data$newvar5<-runif(27,20,100)
map@data$newvar6<-runif(27,20,100)
head(map@data)
ID CD_GEOCODU NM_ESTADO NM_REGIAO newvar1 newvar2 newvar3 newvar4
0 1 11 RONDÔNIA NORTE 94.90707 21.74030 37.29604 59.26561
1 2 12 ACRE NORTE 65.35450 66.58382 40.35771 75.76805
2 3 13 AMAZONAS NORTE 43.70452 26.27472 47.90803 58.78851
3 4 14 RORAIMA NORTE 25.78709 54.68699 40.98279 35.85327
4 5 15 PARÃ NORTE 80.20983 63.18456 39.09327 82.31181
5 6 16 AMAPÃ NORTE 51.39521 51.89274 81.59527 45.32389
newvar5 newvar6 kmeans
0 87.44586 97.69417 1
1 50.92863 87.48382 1
2 64.41917 75.71042 1
3 21.01914 86.78704 1
4 68.11799 87.51693 1
5 75.82186 59.10289 2
palette(brewer.pal(5,"Blues")
palette()
plot(map,col=map@data$kmeans)
download the shapefile: http://www.usp.br/nereus/? data=brazil (Federative units)