How to make stat_binhex shown on the log scale in ggplot2

I have a 2d hexagonal density graph with many dots. I would like graphs in hexagons to be displayed on a logarithmic scale, but I cannot figure out how to do this through ggplot2.

Here is a simple example:

x <- runif(1000, 50, 100) y <- rnorm(1000, mean = 10, sd = 8) df <- as.data.frame(cbind(x, y)) ggplot(df, aes(x, y)) + stat_binhex() 
+5
source share
1 answer

There is aesthetics fill , which defaults to ..count.. unless you specify it in stat_binhex . The code below creates the same plot as the source code.

 ggplot(df, aes(x, y)) + stat_binhex(aes(fill=..count..)) 

enter image description here

If you want to have a log scale for calculations, then the solution is pretty straight forward:

 ggplot(df, aes(x, y)) + stat_binhex(aes(fill=log(..count..))) 

enter image description here

+7
source

Source: https://habr.com/ru/post/1204696/


All Articles