r - 如何在 ggplot2 中创建带阴影的直方图?

标签 r ggplot2

这是一个基于 R 的例子

hist(diamonds$carat,
     col="black",
     density=25,
     angle=60)

enter image description here

我无法使 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()

enter image description here

关于r - 如何在 ggplot2 中创建带阴影的直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64279954/

相关文章:

r - 如何消除bigglm中的 “NA/NaN/Inf in foreign function call (arg 3)”

r - 如何强制显示带有 ggplot2 方面的空图?

r - 具有极值的 ggplot

r - 如何重命名表行 tbl_summary?

python - 从一个数据框中的多个 .csv 和 cbind 中提取相同的列(不同长度) - R

r - 理解 rowwise() 和 c_across()

r - 在ggplot2中按模态排序facet_grid或facet_wrap网格

r - 如何使用 ggplot2 和刻度格式化带有指数的轴标签?

r - 从坐标点创建分区统计图

r - ggplot 中的嵌套面板