0
E.g.中獲得一致的透明度(alpha)如何在ggplot2(版本2.2.0)
tmp_df <-
expand.grid(group = 1:2, x = 1:3)
tmp_df$y <- 1:6
tmp_df$alpha <- c(0.1, 0.1, 0.1, 0.75, 0.1, 1)
p1 <- ggplot(tmp_df, aes(x, y, alpha = alpha)) +
geom_bar(stat = 'identity') +
facet_grid(group ~ .)
tmp_df2 <- tmp_df
tmp_df2$alpha <- 0.1
p2 <- ggplot(tmp_df2, aes(x, y, alpha = alpha)) +
geom_bar(stat = 'identity') +
facet_grid(group ~ .)
這樣:
> tmp_df
group x y alpha
1 1 1 1 0.10
2 2 1 2 0.10
3 1 2 3 0.10
4 2 2 4 0.75
5 1 3 5 0.10
6 2 3 6 1.00
> tmp_df2
group x y alpha
1 1 1 1 0.1
2 2 1 2 0.1
3 1 2 3 0.1
4 2 2 4 0.1
5 1 3 5 0.1
6 2 3 6 0.1
現在考慮:
gridExtra::grid.arrange(p1, p2, ncol = 2)
產生如下圖(P1是在左邊,P2上右):
我們看到雖然ggplot
在呈現一個小平面圖內的alpha級別一致(特別是0.1級)方面沒有問題,但是在數據中製作兩個具有不同級別alpha
的圖似乎會導致不一致的結果。即右側的酒吧比預期的要暗得多。我怎樣才能解決這個問題?