在 ggplot2 中为具有不同颜色深度的地图着色
Coloring a map with different color depths in ggplot2
我正在尝试绘制一张用特定颜色“#2D3E50”着色的巴西地图。但是,在地图上使用这种颜色从最小区域(浅色)到最大区域(深色)着色是行不通的。请参阅下面我尝试为不同比例插入的所选颜色。
library(geobr)
library(ggplot2)
library(cowplot)
library(RColorBrewer)
library(dplyr)
dados <- structure(
list(X = 1:27,
uf = c("Acre", "Alagoas", "Amapá",
"Amazônas", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo",
"Goiás", "Maranhão", "Mato Grosso do Sul", "Mato Grosso", "Minas Gerais",
"Paraíba", "Paraná", "Pará", "Pernambuco", "Piauí", "Rio de Janeiro",
"Rio Grande do Norte", "Rio Grande do Sul", "Rondônia", "Roraima",
"Santa Catarina", "São Paulo", "Sergipe", "Tocantins"),
AreaTotal = c(0, 0.01, 0.07, 0, 0.6, 0, 0, 0.23, 0.14, 0.24, 1.14, 0.6, 1.96,
0, 1.01, 0.21, 0, 0.03, 0.03, 0, 0.83, 0.03, 0.03, 0.64, 1.4,
0, 0.15)), class = "data.frame", row.names = c(NA, -27L))
states <- read_state(code_state = "all",year = 2019)
states$name_state <- tolower(states$name_state)
dados$uf <- tolower(dados$uf)
states <- dplyr::left_join(states, dados, by = c("name_state" = "uf")); states
no_axis <- theme(axis.title=element_blank(),
axis.text=element_blank(),
axis.ticks=element_blank())
ggplot() +
geom_sf(data=states, aes(fill = AreaTotal), color=NA, size=.15) +
no_axis + labs(size=8) + scale_fill_distiller(palette = "2D3E50", name="Áreas", limits = c(0,2))
Warning message:
In pal_name(palette, type) : Unknown palette 2D3E50
看到自动填充了绿色,而且颜色反了,颜色越深越低
RColorBrewer 包不包含名为 #2D3E50 的调色板。因此,足以详细说明具有各自阴影的颜色序列,即低值和高值的颜色,即:low = "white", high = "#2D3E50".
ggplot() +
geom_sf(data = states, aes(fill = AreaTotal)) +
no_axis +
labs(size = 8) +
scale_fill_gradient(low = "white", high = "#2D3E50", name = "Áreas", limits = c(0, 2))
我正在尝试绘制一张用特定颜色“#2D3E50”着色的巴西地图。但是,在地图上使用这种颜色从最小区域(浅色)到最大区域(深色)着色是行不通的。请参阅下面我尝试为不同比例插入的所选颜色。
library(geobr)
library(ggplot2)
library(cowplot)
library(RColorBrewer)
library(dplyr)
dados <- structure(
list(X = 1:27,
uf = c("Acre", "Alagoas", "Amapá",
"Amazônas", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo",
"Goiás", "Maranhão", "Mato Grosso do Sul", "Mato Grosso", "Minas Gerais",
"Paraíba", "Paraná", "Pará", "Pernambuco", "Piauí", "Rio de Janeiro",
"Rio Grande do Norte", "Rio Grande do Sul", "Rondônia", "Roraima",
"Santa Catarina", "São Paulo", "Sergipe", "Tocantins"),
AreaTotal = c(0, 0.01, 0.07, 0, 0.6, 0, 0, 0.23, 0.14, 0.24, 1.14, 0.6, 1.96,
0, 1.01, 0.21, 0, 0.03, 0.03, 0, 0.83, 0.03, 0.03, 0.64, 1.4,
0, 0.15)), class = "data.frame", row.names = c(NA, -27L))
states <- read_state(code_state = "all",year = 2019)
states$name_state <- tolower(states$name_state)
dados$uf <- tolower(dados$uf)
states <- dplyr::left_join(states, dados, by = c("name_state" = "uf")); states
no_axis <- theme(axis.title=element_blank(),
axis.text=element_blank(),
axis.ticks=element_blank())
ggplot() +
geom_sf(data=states, aes(fill = AreaTotal), color=NA, size=.15) +
no_axis + labs(size=8) + scale_fill_distiller(palette = "2D3E50", name="Áreas", limits = c(0,2))
Warning message:
In pal_name(palette, type) : Unknown palette 2D3E50
看到自动填充了绿色,而且颜色反了,颜色越深越低
RColorBrewer 包不包含名为 #2D3E50 的调色板。因此,足以详细说明具有各自阴影的颜色序列,即低值和高值的颜色,即:low = "white", high = "#2D3E50".
ggplot() +
geom_sf(data = states, aes(fill = AreaTotal)) +
no_axis +
labs(size = 8) +
scale_fill_gradient(low = "white", high = "#2D3E50", name = "Áreas", limits = c(0, 2))