这是一个基于 R 的例子
hist(diamonds$carat,
col="black",
density=25,
angle=60)
我无法使 ggplot 版本工作,而且我在 www: 中找不到任何内容:
library(ggplot2)
ggplot(diamonds, aes(carat)) +
geom_histogram() + theme_bw()
背景:在大多数情况下我不打印颜色,所以我更喜欢按样式编码而不是填充颜色。
最佳答案
这里有一个 reprex,展示了一种使用 ggpattern
的方法:
devtools::install_github("coolbutuseless/ggpattern")
library(ggpattern)
library(ggplot2)
ggplot(data = diamonds, aes(x = carat)) +
stat_bin(geom = "bar_pattern",
breaks = 0:10 * 0.5,
fill = "white",
color = "black",
pattern_fill = "gray50",
pattern_angle = 60,
pattern_density = 0.3,
pattern_spacing = 0.01,
pattern_key_scale_factor = 1) +
theme_classic()
关于r - 如何在 ggplot2 中创建带阴影的直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64279954/