2016-07-11 99 views
2

我想繪製一些boxlot作爲半透明。當我設置alpha值時,只調整了填充透明度,而不是邊框​​/筆觸/顏色。ggplot:爲整個圖層添加alpha值

任何想法如何使整個幾何圖層透明?

library(ggplot2) 
ggplot(mtcars, aes(factor(cyl), mpg)) + 
    geom_boxplot(aes(fill = factor(cyl), color = factor(cyl)), alpha = 0) 

enter image description here

回答

3

這不會開箱,因爲多邊形ggplot2僅適用於alphafill,不colour。爲了解決這個問題,我們將通過採用低級內部結構並在需要的地方添加alpha映射來應用以下臨時修補程序。

結帳the following gist。不會發布在這裏,因爲它太長。

ggplot(mtcars, aes(factor(cyl), mpg)) + 
    geom_boxplot(aes(fill = factor(cyl), color = factor(cyl)), alpha = 0.4, size = 1.4) 

前: enter image description here

後: enter image description here

+0

感謝@tonytonov! – Deena

+0

不客氣! – tonytonov