2013-05-08 90 views
6

我用ggplot2創建了兩個透明的重疊直方圖。如何使用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 「當酒吧重疊。這可能嗎?

+0

據我所知,紋理是不可能的'ggplot2'。 – Arun 2013-05-08 21:23:56

+0

是否可以使用函數hist()或truehist()(來自MASS庫)的紋理? – user2363777 2013-05-09 16:54:38

回答

8

這怎麼樣(沒有紋理仍然)?

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

相關問題