1

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)

hexbin

mindlessgreen
  • 11,059
  • 16
  • 68
  • 113

1 Answers1

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))

highBandWidth
  • 16,751
  • 20
  • 84
  • 131
jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • What is `..count..`? When I run your code it says `Error in cut(count, breaks = pretty(count, n = 5)) : object 'count' not found` – highBandWidth Mar 01 '17 at 00:12