【发布时间】:2020-04-10 17:42:00
【问题描述】:
我正在尝试制作一张覆盖在路线图上的地图。为了使路线图可见,我应用了一个非美学的 alpha 参数。执行此操作时,连续填充比例图例不会应用相同的 alpha 级别。我想要的是对图例应用与地图中所做的相同的 alpha。如何解决这个问题?
library(tigris)
library(ggplot2)
library(sf)
options(tigris_class = "sf")
texas <- counties(48)
texas$fill <- rnorm(254, 50, 20)
ggplot(texas) +
geom_sf(aes(fill = fill, alpha = .5), color = "light grey") +
scale_fill_distiller(palette = "Spectral")
此解决方案应用了 alpha,但它删除了图例的渐变。
ggplot(texas) +
geom_sf(aes(fill = fill, alpha = .5), color = "light grey") +
scale_fill_distiller(palette = "Spectral") +
guides(fill = guide_legend(override.aes = list(alpha = 0.5)), alpha = FALSE)
【问题讨论】: