基于密度的facet_grid中每个图的独立alpha

时间:2017-02-24 07:35:48

标签: r ggplot2 facet facet-grid

我正在使用facet_grid构建stat_hexbin但是我希望alpha值对于每个构面图都是独立的。

我目前正在使用以下代码:

ggplot (data, aes (x, y , fill = z)) +
  stat_binhex(bins=20, aes(alpha = ..count..)) +
  facet_grid(. ~ z) +
  guides(alpha = F) +
  coord_equal() + 
  theme_bw()

产生以下图: hexbin facet

但是,..count..定义的alpha值在aes内的stat_binhex之外应用时无效。

我想表明右边的 90 分组中存在一些聚类,围绕(100,0)区域,但是这些颜色非常苍白,因为 10 分组(最左边的图)中的(0,0)周围有如此沉重的聚类,这会使α偏斜。

主要问题:如何让Alpha独立于每个方面,但仍然与计数/密度相关联,以更好地显示“70'”中的聚类。和' 90'组?

非常感谢!

数据:

# rounded x and y, from 2 days of 365
structure(list(x = c(-24, 41, 43, 14, 9, 30, 8, -14, -45, 42, 
65, 39, 43, 49, 39, 61, -53, -16, 29, 27, 9, 6, -61, 20, 5, -30, 
-10, 75, 94, 28, 70, 44, -11, 26, 29, 33, 26, -35, 20, 40, 7, 
4, 14, 4, -41, -7, -21, 95, 20, 50, 63, 31, 47, 19, 20, 19, 23, 
-25, 29, -8, -73, 13, -82, 4, -29, 3, 9, 3, 35, 45, 64, -14, 
-4, 34, 13, 12, 20, 13, 15, -17, 12, 19, -55, -49, 95, -19, 45, 
94, 23, 29, 22, -91, -39, -35, -3, 63, 2, 5, 30, 62, 1, 4, -61, 
-6, -2, 5, -26, -23, 5, 6, 8, 45, 104, -7, 8, 44, -43, -8, 9, 
12, 29, 30, 69, 90, 12, -28, -10, -9, 49, 60, 32, 43, -11, 12, 
28, 91, 11, 13, 43, 61, 11, 12, 28, 31, 47, 12, 13, 30, 46, 66, 
98, 11, 12, 29, 31, 44, 64, -11, 14, 48, 62, 96, 10, 11, 12, 
29, 67, 30, 93, -10, -9, 44, 101, -28, 34, 46, 10, 27, 30, 61, 
8, 24, -7, -2, 52, 65, 5, -43, 41, 45, 91, -24, -23, 37, 73, 
97, -61, 63, 57, 52, -37, -35, 19, 24, 110, -91, -5, -17, 95, 
13, 85, -52, -50, 78, 30, 37, -8, -27, 19, -78, -75, 52, 42, 
-11, -37, 27, 62, 78, -16, -56, 41), y = c(-100, -95, -95, -92, 
-88, -86, -84, -82, -81, -78, -73, -72, -71, -70, -69, -68, -67, 
-67, -64, -63, -62, -59, -58, -57, -56, -54, -54, -54, -54, -52, 
-52, -49, -48, -48, -48, -47, -46, -45, -45, -45, -44, -42, -41, 
-40, -39, -39, -38, -38, -37, -36, -36, -35, -35, -34, -34, -33, 
-33, -32, -32, -31, -30, -30, -29, -29, -28, -27, -27, -26, -26, 
-26, -26, -25, -25, -25, -24, -23, -23, -22, -22, -21, -21, -21, 
-20, -20, -19, -18, -18, -18, -17, -17, -16, -14, -14, -14, -13, 
-13, -12, -12, -12, -12, -11, -11, -10, -10, -10, -10, -9, -9, 
-9, -9, -9, -9, -9, -8, -8, -8, -7, -7, -7, -7, -6, -6, -6, -6, 
-5, -4, -4, -4, -4, -4, -3, -3, -2, -2, -2, -2, -1, -1, -1, -1, 
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 
3, 4, 4, 4, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 
10, 11, 11, 11, 11, 12, 13, 14, 14, 14, 15, 15, 15, 16, 16, 18, 
19, 20, 21, 23, 23, 24, 24, 24, 26, 27, 28, 28, 29, 30, 32, 32, 
32, 36, 36, 41, 42, 44, 48, 48, 50, 51, 57, 60, 62, 76, 76, 85, 
89, 93), z = c(90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 
90, 90, 90, 90, 90, 70, 70, 70, 70, 70, 90, 70, 70, 70, 70, 90, 
90, 70, 90, 70, 50, 70, 70, 70, 70, 70, 50, 70, 50, 50, 50, 50, 
70, 50, 50, 90, 50, 70, 70, 50, 70, 50, 50, 50, 50, 50, 50, 30, 
90, 30, 90, 30, 50, 30, 30, 30, 50, 50, 70, 30, 30, 50, 30, 30, 
30, 30, 30, 30, 30, 30, 70, 70, 90, 30, 50, 90, 30, 30, 30, 90, 
50, 50, 10, 70, 10, 10, 30, 70, 10, 10, 70, 10, 10, 10, 30, 30, 
10, 10, 10, 50, 90, 10, 10, 50, 50, 10, 10, 10, 30, 30, 70, 90, 
10, 30, 10, 10, 50, 70, 30, 50, 10, 10, 30, 90, 10, 10, 50, 70, 
10, 10, 30, 30, 50, 10, 10, 30, 50, 70, 90, 10, 10, 30, 30, 50, 
70, 10, 10, 50, 70, 90, 10, 10, 10, 30, 70, 30, 90, 10, 10, 50, 
90, 30, 30, 50, 10, 30, 30, 70, 10, 30, 10, 10, 50, 70, 10, 50, 
50, 50, 90, 30, 30, 50, 70, 90, 70, 70, 70, 70, 50, 50, 30, 30, 
90, 90, 30, 30, 90, 30, 90, 70, 70, 90, 50, 50, 50, 50, 50, 90, 
90, 70, 70, 70, 70, 70, 90, 90, 90, 90, 90)), .Names = c("x", 
"y", "z"), row.names = c(NA, -231L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x0000000000330788>)

0 个答案:

没有答案