Adjust hexbin legend breaks

橙三吉。 提交于 2019-12-02 13:16:47

问题


In this example of a hexbin plot, the legend on the right has 10 levels/classes/breaks. Does anyone know how to change the number of levels? Say I want to change it to 5 or something.

  library(hexbin)
  x=rnorm(1000, mean = 50, sd = 1)
  y=rnorm(1000, mean = 30, sd = 0.5)
  df <- data.frame(x,y)
  #plot(df)

  hb <- hexbin(x=df$x, df$y)
  #hb <- hexbin(x=df$x, df$y,xbins=30)
  #plot(hb)
  gplot.hexbin(hb)


回答1:


Like this?

gplot.hexbin(hb,colorcut=5)

And here's approximately the same thing using ggplot.

library(ggplot2)
ggplot(df, aes(x,y))+
  geom_hex(aes(fill=cut(..value..,breaks=pretty(..value..,n=5))),bins=15)+
  scale_fill_manual("Count",values=grey((5:0)/6))



来源:https://stackoverflow.com/questions/27706115/adjust-hexbin-legend-breaks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!