這里的想法是為每個geom具有相同審美的圖例繪制一個圖例。在下面的示例中,生成的圖例假設這兩個不同的圖層具有相同的比例,從而生成此地圖。
因此,我希望圖中的圖例被分成兩部分,因此我可以scale_fill_*為每一層更改這些圖例。
我知道這個解決方案:
謝謝。
uj5u.com熱心網友回復:
聽起來好像您正在尋找ggnewscale允許具有相同美感的多個比例和指南的包:
library(tidyverse)
library(sf)
library(geobr)
library(ggnewscale)
pal1 <- scales::hue_pal()(8)[1:4]
pal2 <- scales::hue_pal()(8)[5:8]
ggplot()
geom_sf(data = mun[[1]], aes(fill = index))
scale_fill_manual(values = pal1)
new_scale_fill()
geom_sf(data = mun[[2]], aes(fill = index))
scale_fill_manual(values = pal2)

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/376446.html
