0

我正在尝试绘制一张带有特定颜色“#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

看到它自动填充绿色,而且颜色是相反的,因为较暗的颜色显示较低的区域。

4

1 回答 1

0

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))

于 2021-02-25T17:19:08.847 回答