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
的图似乎会导致不一致的结果。即右侧的酒吧比预期的要暗得多。我怎样才能解决这个问题?