How to create black and white transparent overlapping histograms using ggplot2?

给你一囗甜甜゛ 提交于 2019-12-09 05:59:41

问题


I used ggplot2 to create two transparent overlapping histograms.

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

The resulting plot looks great, but it's in color. I need a grayscale or black/white plot.

Using "scale_fill_grey()" results in a plot with transparency that is very difficult to "read".

Ideally, I would like a black/white plot that uses texture instead of color, for instance, cross hatching: "///" for one condition, "\\\" for the other condition, resulting in "XXX" when the bars overlap. Is this possible?


回答1:


How about this (no texturing still)?

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



来源:https://stackoverflow.com/questions/16449576/how-to-create-black-and-white-transparent-overlapping-histograms-using-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!