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

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 is in color. I need a grayscale or black and white plot.

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

Ideally, I need a black and white chart that uses a texture instead of color, for example, cross-hatching: "///" for one condition, "\\\" for another condition, resulting in "XXX" when the bars overlap. Is it possible?

+6
source share
1 answer

How about this (no texturing yet)?

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

enter image description here

+8
source

Source: https://habr.com/ru/post/944569/


All Articles