2

我正在使用该ggplot2 stat_summary_hex函数绘制客户流失图。

stat_summary_hex(aes(x = Lon, y = Lat, z = Churn),
   bins=100, colour = NA, geom = "hex", fun = function(x) sum(x))

ScaleFill <- scale_fill_gradient2(low = "blue", high = "orange", na.value = NA)

stat_summary_hex 绘制在底图上,get_map因此我想设置alpha比例,使接近 0 的汇总值的值为alpha0。但是,它看起来stat_summary_hex不承认alpha美学。

有人有映射的例子stat_summary_hexalpha

4

1 回答 1

2

我通过设置 = TRUE 找到了一种解决方法drop,然后stat_summary_hex在结果小于我的阈值时更改函数以返回 NA:

stat_summary_hex(aes(x = Lon, y = Lat, z = Churn),
  bins=100, colour = NA, geom = "hex", drop = TRUE,
  fun = function(x) if(abs(sum(x)) > 5) {sum(x)} else {NA})
于 2013-08-30T21:04:12.277 回答