我試圖結合alpha並填充ggplot2。它在我使用geom_bar(或geom_points,用於顏色)時起作用,但當我使用geom_boxplot時,alpha圖例不起作用。阿爾法和ggplot2 boxlot中填充傳說?
library(data.table)
library(ggplot2)
dt = data.table(x = rep(1:5,6), y = rnorm(30), tag1 = rep(c('hey', 'what'), 15), tag2 = rep(c('yeah', 'yeah', 'so', 'so', 'so'), 6))
它適用於酒吧:
ggplot(dt[, list(y=mean(y)), by=list(x, tag1, tag2)], aes(x=x, y=y, fill=tag1, alpha=tag2, group=interaction(x,tag1,tag2))) + geom_bar(stat = 'identity', position = 'dodge')
但不適合箱線圖 - 阿爾法傳說是空的。
ggplot(dt, aes(x=x, y=y, fill=tag1, alpha=tag2, group=interaction(x,tag1,tag2))) + geom_boxplot()
一個簡單的版本可以在沒有補做 - 它看起來像條默認爲灰色/淺灰色和箱線圖默認爲白色/ lightwhite:
ggplot(dt[, list(y=mean(y)), by=list(x, tag2)], aes(x=x, y=y, alpha=tag2, group=interaction(x,tag2))) + geom_bar(stat = 'identity')
ggplot(dt, aes(x=x, y=y, alpha=tag2, group=interaction(x,tag2))) + geom_boxplot()
但我真的不知道如何解決這個問題..有什麼想法?
謝謝!奇怪的是,酒吧和boxplot之間有不同的行爲,並且它必須手動修復,但這絕對有效!我同意在這個例子中alpha是令人困惑的。在我的最終結果中,我使用alpha來區分理論結果(透明)和由於抽樣錯誤而導致的更加混亂的結果等。所以我認爲它更具可讀性。 – benjamin