【问题标题】:geom_hexbin map bincount to alphageom_hexbin 将 bincount 映射到 alpha
【发布时间】:2016-09-12 09:10:41
【问题描述】:

我希望 geom_hex bincount 为 alpha,就像 here 所做的那样。

不知何故它对我不起作用,可能是什么问题? (ggplot2 的开发版?):

library(ggplot2)
library(reshape2)

dm <- melt(diamonds, measure.var = c('depth','carat'))

ggplot(dm, aes(y = price, fill = variable, x = value)) + 
  facet_wrap(~variable, ncol = 1, scales  = 'free_x') + 
  stat_binhex(aes(alpha = ..count..), colour = 'grey80') + 
  scale_alpha(name = 'Frequency', range = c(0,1)) + 
  theme_bw() + 
  scale_fill_manual('Variable', values = setNames(c('darkblue','yellow4'), c('depth','carat')))

Error in eval(expr, envir, enclos) : object 'count' not found

会话信息:

R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=nl_NL.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] hexbin_1.27.1      reshape2_1.4.1     ggplot2_2.1.0.9000

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.7      lattice_0.20-33  assertthat_0.1   grid_3.2.3       plyr_1.8.4       gtable_0.2.0     magrittr_1.5     scales_0.4.0     stringi_1.1.1    tools_3.2.3      stringr_1.1.0    munsell_0.4.3   
[13] rsconnect_0.4.3  colorspace_1.2-6 tibble_1.2 

【问题讨论】:

标签: r ggplot2


【解决方案1】:

从那时起,包中发生了一些变化,改变了 ..count....density..hexbin 的工作方式。 @RichardTelford 的链接指向 ..density.. 的已解决 github 问题,但 ..count.. 功能尚未恢复。但是,我们可以简单地使用..value..

ggplot(dm, aes(y = price, fill = variable, x = value)) + 
  facet_wrap(~variable, ncol = 1, scales  = 'free_x') + 
  stat_binhex(aes(alpha = ..value..), colour = 'grey80') + 
  scale_alpha(name = 'Frequency', range = c(0,1)) + 
  theme_bw() + 
  scale_fill_manual('Variable', values = setNames(c('darkblue','yellow4'), c('depth','carat')))

我已将此问题报告为on github

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-09
    • 2016-04-09
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 2019-05-27
    • 1970-01-01
    • 2023-02-11
    相关资源
    最近更新 更多