Прежде всего, я хотел бы извиниться за мой плохой английский.Я пытаюсь вписать свои данные в карту Бразилии, и вот что я получил:
Обратите внимание, что мои данные идут от -0,53 до 0,73 иэти значения имеют самые темные цвета на графике.Мне нужна легенда с -1 до 1, в которой мои выбросы (-0,53 / 0,73) имеют более светлые цвета на карте, а -1,0 / 1,0 - самые темные цвета в легенде.Кроме того, я хотел бы, чтобы отрицательные значения были красными, а положительные - голубыми.Как я могу это сделать?
Это код, который я сейчас использую:
# Packages
library(maptools)
library(descr)
library(RColorBrewer)
library(plotrix)
# Reading shape files
estados <- readShapePoly(fn = 'estados_2010.shp')
estados2 <- readShapePoly(fn = 'estados_2010.shp')
# Adding an order vector in the data frame
estados@data$order <- 1:nrow(estados@data)
# Data to fit in the map
teste <- c(0.567072774466371,
-0.144934811865636,
0.595967865326944,
0.479904421295722,
0.251495518688696,
0.195815073242536,
0.548223329774688,
0.463845521774005,
0.272145251828454,
0.580334048486482,
0.649672015127772,
0.584054575484519,
0.671373957229477,
0.436391947145788,
0.522605768431274,
0.641067907529059,
0.570339843565797,
0.381297082036819,
0.474587396032187,
0.462810571821925,
0.558684078070584,
-0.197881941278306,
0.720551728476599,
0.489189630257170,
-0.538560893510226,
0.732280520987057,
0.555364159479124)
# Adding the data vector in the data frame
estados@data$dados <- teste
# Colours
myPaletteBlue <- brewer.pal(9,'RdBu')
createColors <- colorRampPalette(myPaletteBlue, bias=3.3)
myColorsBlue <- createColors(nrow(estados@data))
# Counting the number of colours
numberColors <- length(unique(myColorsBlue))
cuts <- quantile(estados@data$dados,
probs=(0:numberColors)/numberColors)
estados@data$dados2 <- cut(estados@data$dados,breaks = cuts,
include.lowest=T)
# Merging the data
colorOfdados2 <- data.frame(dados2=levels(estados@data$dados2),
colors=unique(myColorsBlue))
estados@data <- merge(estados@data, colorOfdados2)
# Ordering the data frame back to the first order
estados@data <- estados@data[order(estados@data$order),]
# Plot
plot(estados, col=as.character(estados@data$colors),
lty=0)
plot(estados2, add=T) # Destaca as linhas dos estados no mapa
# Legend
color.legend(xl=-70, xr=-60,yb=-25,yt=-26,
legend=c('-0.53','','0.73'),
rect.col=myColorsBlue, gradient='x',
cex=.8, pos=c(1,1,1))