Подскажите как сделать градиентную заливку карты районов Московской области в зависимости от показателя (fill = counties$Value).
Пока сделал так:
Код: Выделить всё
library(broom); library(maps); library(maptools); library(rgeos); library(mapproj); library(scales)
radm <- readRDS("Geo/gadm36_RUS_2_sp.rds") # Карта России
library(sp)
rg <- radm[radm@data$NAME_1 == "Moskva",]
counties <- tidy(rg, region = "NL_NAME_2") # конвертация в формат пригодный для ggplot2
set.seed = 100 # Данные для примера
df <- data.frame(unique(counties$id))
df$Value <- abs(rnorm(nrow(df), mean = 10, sd = 10))
names(df)[1] <- "Distr"
library(dplyr); library(ggplot2)
counties <- left_join(counties, df, by = c("id" = "Distr"))
library(scales)
ggplot() + geom_map(data = counties, aes(map_id = id),
map = counties, fill = counties$Value, color = "white") +
expand_limits(x = counties$long, y = counties$lat) +
scale_fill_gradient(low = "white", high = "blue") + # не получается градиент!!!
coord_map("polyconic")
scale_fill_gradient(low = "white", high = "blue") - это не получается.
Подскажите, что делать?
Спасибо!