您可以使用添加模式ggpattern package https://coolbutuseless.github.io/2020/04/01/introducing-ggpattern-pattern-fills-for-ggplot/
# remotes::install_github("coolbutuseless/ggpattern")
library(ggpattern)
library(ggplot2)
library(dplyr, warn.conflicts=FALSE)
library(tidyr)
d <- iris %>%
group_by(Species) %>%
summarize_all(mean) %>%
gather(key, val, -Species)
ggplot(d, aes(x = Species, y = val, fill = key)) +
geom_col_pattern(position = "dodge",
pattern =
c(
"stripe", "stripe", "stripe", # 3rd col
"stripe", "stripe", "stripe", # 4th col
"none", "none", "none", # 1st col
"crosshatch", "crosshatch", "crosshatch" # 2nd col
),
pattern_angle = c(rep(0, 3),
rep(45, 3),
rep(0, 6)),
pattern_density = .1,
pattern_spacing = .04,
pattern_fill = 'black') +
scale_fill_grey() +
guides(fill = guide_legend(override.aes =
list(
pattern = c("none", "crosshatch", "stripe", "stripe"),
pattern_spacing = .01,
pattern_angle = c(0, 0, 0, 45)
)
))
Created on 2021-01-13 by the reprex package https://reprex.tidyverse.org (v0.3.0)