logscale color values of bins in geom_hex()

363 views
Skip to first unread message

Ben Tupper

unread,
Mar 8, 2016, 11:02:25 PM3/8/16
to ggplot2
Hello,

In the past I think I have been able to logscale the color values of bin cells in a hex bin plot.  I say 'I think' because its based upon a vague memory.  The example below performs linear scaling of the values, but how might I log10() transform color values of the the density plot?


ggplot(diamonds, aes(carat, price)) +
    geom_hex(stat = 'binhex') +
    scale_fill_continuous(low = "gray85", high = "black")


Thanks!
Ben Tupper


> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.3 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] hexbin_1.27.1     ggplot2_2.1.0     gdalUtils_2.0.1.7 ncdf4_1.15        spnc_0.1          raster_2.5-2    
[7] rgdal_0.9-3       sp_1.2-1        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.3       lattice_0.20-33   codetools_0.2-14  digest_0.6.9      foreach_1.4.2     MASS_7.3-45     
 [7] R.methodsS3_1.7.0 plyr_1.8.3        grid_3.2.3        gtable_0.2.0      scales_0.4.0      R.oo_1.19.0     
[13] R.utils_2.1.0     labeling_0.3      iterators_1.0.7   tools_3.2.3       munsell_0.4.3     colorspace_1.2-6


Brandon Hurr

unread,
Mar 9, 2016, 12:03:20 AM3/9/16
to Ben Tupper, ggplot2
Take a look at using the scales package. I believe the trans argument is the one you're after.

https://github.com/hadley/ggplot2/wiki/scales
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Tupper

unread,
Mar 9, 2016, 8:38:38 AM3/9/16
to ggplot2, ben.b...@gmail.com
Perfecto!   Works like a charm,



ggplot(diamonds, aes(carat, price)) +
    geom_hex(stat = 'binhex') +
    scale_fill_continuous(low = "gray85", high = "black", trans = log10_trans())


Cheers and thanks,
Ben
Reply all
Reply to author
Forward
0 new messages