r - R - plot_brmap(州界)
问题描述
我制作了一张巴西城市的地图,plot_brmap()
我想显示州界。
但我不知道该怎么做。我一直在尝试mapa2_data
用透明颜色填充(状态图)并用mapa_data
(城市地图)绘制。但它不起作用。
我一直在尝试:
library(brazilmaps)
library(maptools)
library(RColorBrewer)
# Definindo paleta de cores ----
createColors <- colorRampPalette(c("yellow","red","darkgreen"))
# Definindo cidades e estados ----
cidades_sp_mg <- get_brmap(geo = "City", geo.filter = list(State = c(31,35))
,class = "SpatialPolygonsDataFrame")
estados_sp_mg <- get_brmap(geo = "State", geo.filter = list(State = c(31,35))
,class = "SpatialPolygonsDataFrame")
# Criando Mapa - Cooxupé e Cocapec ----
load(file="dados/data.Rdata")
# Agrupa por razao social e municipio, conta quantas coop. cada municipio tem
dScore_data <- data %>% group_by(cod_municipio_ibge) %>% count()
# Gera mapa das cidades
mapa_data <- plot_brmap(cidades_sp_mg,
data_to_join = dScore_data,
join_by = c("City" = "cod_municipio_ibge"),
var = "n"
)
dScore_data$code_state <- as.numeric(dScore_datac$code_state)
mapa2_data <- plot_brmap(estados_sp_mg,
data_to_join = dScore_data,
join_by = c("State" = "code_state"),
var = "n"
)
MinhasCores_data <- createColors(4)
png("dados/Cities.png", width = 800, height = 600)
print(mapa_data) +
scale_fill_gradientn(colours=MinhasCores_data,name="Qtd.", na.value = "lightgray") +
labs(title="Cities",caption = "Font") +
theme(legend.title = element_text(face="bold"),title = element_text(face="bold"),
plot.title = element_text(hjust = 0.5,size=20),
plot.caption = element_text(hjust = 0.5,size = 10))
+ plot(mapa2_data)
dev.off()
解决方案
library(geobr)
# Define borders SP and MG
mapa_SP <- read_state(code_state="SP", year=2018)
mapa_MG <- read_state(code_state="MG", year=2018)
添加到地图情节geom_sf()
print(mapa_data) +
scale_fill_gradientn(colours=MinhasCores_data,name="Qtd.", na.value = "lightgray") +
labs(title="Cities",caption = "Font") +
theme(legend.title = element_text(face="bold"),title = element_text(face="bold"),
plot.title = element_text(hjust = 0.5,size=20),
plot.caption = element_text(hjust = 0.5,size = 10)) +
geom_sf(data=mapa_SP, fill="transparent", color="black", size=0.8, show.legend = FALSE) +
geom_sf(data=mapa_MG, fill="transparent", color="black", size=0.8, show.legend = FALSE)
推荐阅读
- ionic-framework - Ionic 3 上的 OneSignal 问题
- node.js - 如何检查(预期)对象/数组是否包含量角器中的特定字符串?
- python - 尝试使用 pygame 在 pacman 游戏中进行基本的敌人移动
- c# - .NET CORE Razor Pages Ajax 调用 C# 方法
- php - WordPress CSS 不工作
- php - 与 wamp 的 npm 浏览器同步不起作用
- python - 更改一些条形颜色
- python - 将 pytorch 权重导出到 keras
- ios - 如何在 Firebase 中收到电子邮件验证通知?
- javascript - 错误消息““index”参数应为数字,但它是数字”不清楚