【问题标题】:How to create black and white transparent overlapping histograms using ggplot2?如何使用ggplot2创建黑白透明重叠直方图?
【发布时间】:2013-05-03 05:00:45
【问题描述】:

我使用 ggplot2 创建了两个透明的重叠直方图。

test = data.frame(condition = rep(c("a", "b"), each = 500), value = rep(-1, 1000))
test[1:500,]$value = rnorm(500)
test[501:1000,]$value = rnorm(500) + 2

fig = ggplot(test, aes(x = value, fill = condition)) +
      #scale_fill_grey() +
      geom_histogram(position = "identity", alpha = .5)
fig

生成的图看起来很棒,但它是彩色的。我需要一个灰度图或黑白图。

使用“scale_fill_grey()”会导致绘图的透明度非常难以“阅读”。

理想情况下,我想要一个使用纹理而不是颜色的黑白图,例如,交叉影线:“///”代表一个条件,“\\\”代表另一个条件,导致“XXX”当条重叠时。这可能吗?

【问题讨论】:

  • 据我所知,ggplot2 无法进行纹理处理。
  • 是否可以通过函数 hist() 或 truehist()(来自 MASS 库)使用纹理?

标签: r ggplot2 textures histogram


【解决方案1】:

这个怎么样(仍然没有纹理)?

fig = ggplot(test, aes(x = value, fill = condition)) +
    geom_histogram(position = "identity", alpha = .8) + 
    scale_fill_manual(values=c("grey20", "grey60")) + theme_bw()
fig

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 2012-12-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    • 2014-06-22
    相关资源
    最近更新 更多