<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><div><font face="times new roman, new york, times, serif"><br></font></div><div><span style="font-family: 'times new roman', 'new york', times, serif;">#Olá,tudo bem!</span><br></div><div><font face="times new roman, new york, times, serif">#Gostaria de saber como plotar o nome de município e uma quantidade num mapa:</font></div><div><font face="times new roman, new york, times, serif">#Tenho uma planilha com os 645 municípios do Estado de São Paulo, das quais como CMR, coloco 5 deles num data.frame:</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif">cidade=c("São Paulo","Diadema","São Bernardo do Campo","Santo André","São Caetano")</font></div><div><font face="times new roman, new york, times,
 serif">valor=c(6000,450,2500,2000,1000)</font></div><div><font face="times new roman, new york, times, serif">saopaulo=data.frame(cidade,valor)</font></div><div><font face="times new roman, new york, times, serif">saopaulo</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif">#Tenho os arquivos dbf, sbn, sbx, shp e shx e uso os seguintes comandos:</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif" style="text-decoration: underline;">###      1-Carregando arquivo shape</font></div><div><font face="times new roman, new york, times, serif">library(maptools);</font></div><div><font face="times new roman, new york, times, serif">sp = readShapePoly("C:/r/shapefile-sp-ibge/35mu500gc.shp")</font></div><div><font face="times new roman, new york, times,
 serif"><br></font></div><div><font face="times new roman, new york, times, serif" style="text-decoration: underline;">###      2-Carregando planilha com o nome do município e valor</font></div><div><font face="times new roman, new york, times, serif">require(RODBC);cnct = odbcConnectExcel2007(file.choose())</font></div><div><font face="times new roman, new york, times, serif">saopaulo = sqlQuery(cnct, "select * from \"Plan1$\" ");odbcClose(cnct);attach(saopaulo);saopaulo</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif">sp.dados <- attr(sp, "data")</font></div><div><font face="times new roman, new york, times, serif">sp.dados$indice <- 1:dim(sp.dados)[1]</font></div><div><font face="times new roman, new york, times, serif">sp.dados <- merge(sp.dados,
 saopaulo)</font></div><div><font face="times new roman, new york, times, serif">sp.dados <- sp.dados[order(sp.dados$indice), ]</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif" style="text-decoration: underline;">###       3-Atribuindo cores para cada intervalo</font></div><div><font face="times new roman, new york, times, serif">intervalo = c(0,1,500,1000,5000,9999)</font></div><div><font face="times new roman, new york, times, serif">cat3 <- findInterval(saopaulo$valor,intervalo )</font></div><div><font face="times new roman, new york, times, serif">options(scipen=10)</font></div><div><font face="times new roman, new york, times, serif">table(cat3)</font></div><div><font face="times new roman, new york, times, serif">cores3 <-
 c("white","yellow","blue","green","red","black")</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif" style="text-decoration: underline;">###       4-Plotando o mapa</font></div><div><font face="times new roman, new york, times, serif">#par(mar=c(0,0,0,0))</font></div><div><font face="times new roman, new york, times, serif">windows(width=19, height=9, xpos=0, ypos=0,pointsize = 13,rescale="fixed")</font></div><div><font face="times new roman, new york, times, serif">plot(sp, col=cores3[cat3]);legend("bottomleft",leglabs( c(0,1,500,1000,5000,9999), "<", ">"),fill=cores3, bty="n",text.width=10)</font></div><div><font face="times new roman, new york, times, serif"><br></font></div><div><font face="times new roman, new york, times, serif" style="text-decoration: underline;">###       <span style="color: rgb(255, 0,
 0);">5</span>-Colocando números</font></div><div><font face="times new roman, new york, times, serif">sp.polgns<-attr(sp,"polygons")</font></div><div><font face="times new roman, new york, times, serif">sp.cntrd<-lapply(sp.polgns,slot,"labpt")</font></div><div><font face="times new roman, new york, times, serif">text(as.character(saopaulo$valor),cex=0.5)</font></div><div><font face="times new roman, new york, times, serif">sp.x<-sapply(sp.cntrd,function(x) x[1])</font></div><div><font face="times new roman, new york, times, serif">sp.y<-sapply(sp.cntrd,function(x) x[2])</font></div><div><font face="times new roman, new york, times, serif">text(sp.x,sp.y,as.character(saopaulo$valor),cex=0.3)</font></div><div><br></div><div><font face="times new roman, new york, times, serif" style="color: rgb(255, 0, 0);">#Dúvidas:</font></div><div><font face="times new roman, new york, times, serif" style="font-weight: bold;">#1- Como colocar os nomes dos
 municípios (saopaulo$cidade) em cima dos números no item 5 (para que não se sobreponham)?</font></div><div><font face="times new roman, new york, times, serif"><span style="font-weight: bold;">#2- Quais são os comandos para se plotar uma determinada região. Ex: Municípios do ABC ou Litoral Paulista (somente municípios de interesse no mapa)?</span></font></div><div><br></div><div><font face="times new roman, new york, times, serif">Muito obrigado!</font></div><div><font face="times new roman, new york, times, serif">Felicidades...</font></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; background-color: transparent; font-style: normal;"><font face="times new roman, new york, times, serif">Alexandro Vieira Lopes</font></div></div></div></body></html>