make ggplot2 :: stat_bin2d显示密度而不是计数

ego*_*go_ 2 r ggplot2

有可能让它显示组内密度而不是计数吗?

library(ggplot2);data(diamonds)
ggplot(diamonds, aes(carat, depth)) +  
  stat_bin2d(bins=40)+ facet_wrap(~color)
Run Code Online (Sandbox Code Playgroud)

这样可以更容易地比较各组之间的模式,因为有些组可能自然会更多.

问题与以下内容略有相似:如何在每列(按X轴)缩放(标准化)ggplot2 stat_bin2d的值,这也是缺少答案的.

Rol*_*and 9

ggplot(diamonds, aes(carat, depth)) +  
  stat_bin2d(bins=40, aes(fill = ..density..))+ facet_wrap(~color)
Run Code Online (Sandbox Code Playgroud)

结果情节

或者你会对核密度估计感到满意吗?

ggplot(diamonds, aes(carat, depth)) +  
  stat_density2d(aes(fill = ..density..), geom = "tile", contour = FALSE, n = 25) + 
  facet_wrap(~color) +
  scale_fill_gradient(low = "light blue", high = "dark red")
Run Code Online (Sandbox Code Playgroud)

结果情节

或者使用默认网格:

ggplot(diamonds, aes(carat, depth)) +  
  stat_density2d(aes(fill = ..density..), geom = "tile", contour = FALSE) + 
  facet_wrap(~color) +
  scale_fill_gradient(low = "light blue", high = "dark red")
Run Code Online (Sandbox Code Playgroud)

结果情节