gradient breaks in a ggplot stat_bin2d plot

前端 未结 2 982
有刺的猬
有刺的猬 2020-12-17 09:00

I have a 2d histogram created with stat_bin2d in the ggplot2 package. I\'d like to control both the number of breaks in the color gradient, as well

相关标签:
2条回答
  • 2020-12-17 09:20

    Me thinks you probably want the less talked about cousin of scale_colour_gradient2(), scale_fill_gradient2()

    Using your data:

    p + scale_fill_gradient2(breaks=c(1,2,3,4,5,6))
    

    Also note the optional parameters low, mid, and high for additional controls.

    enter image description here

    0 讨论(0)
  • 2020-12-17 09:22

    here is an example combining cut and bin2d:

    p <- ggplot(df, aes(x, y, fill=cut(..count.., c(0,6,8,9,Inf))))
    p <- p + stat_bin2d(bins = 20)
    p + scale_fill_hue("count")
    

    As there are many ways to make the breaks arbitrary, if you define clearly what you want, probably you can get a better answer.

    enter image description here

    0 讨论(0)
提交回复
热议问题