66684

Adjust hexbin legend breaks

Question:

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)

<img alt="hexbin" class="b-lazy" data-src="https://i.stack.imgur.com/tiEn3.jpg" data-original="https://i.stack.imgur.com/tiEn3.jpg" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Answer1:

Like this?

gplot.hexbin(hb,colorcut=5)

<img alt="" class="b-lazy" data-src="https://i.stack.imgur.com/OBtJ8.png" data-original="https://i.stack.imgur.com/OBtJ8.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

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

<img alt="" class="b-lazy" data-src="https://i.stack.imgur.com/Nbmzp.png" data-original="https://i.stack.imgur.com/Nbmzp.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Recommend

  • Select Earliest Order for a set of tests in a daterange SQL
  • Legend control with two data frames of different x-scales and different geoms in ggplot2
  • several hexbin plots on one PDF page in R
  • Dynamic DropDownLists In MVC 4 Form
  • R ggvis interactive slider for calculating y values (e.g. for background correction)
  • how to delete a file's on uninstall the android application? [duplicate]
  • Save and retrieve an image file in LibGDX
  • R Impute NA's by Linear Increase Depending on Time Interval
  • How to model a mixture of finite components from different parametric families with JAGS?
  • R Leaflet Legend: specify order instead of alphabetical
  • Using : for multiple slicing in list or numpy array
  • Group variable in cobol
  • Greek letters in legend in R
  • Oracle ListaGG, Top 3 most frequent values, given in one column, grouped by ID
  • iOS 6 dateFromString returns wrong date
  • rapply over a nested list in R
  • Geom_jitter colour based on values
  • For loop with if condition on multiple R functions
  • Calculating ratio of reciprocated ties for each node in igraph
  • How to create CGPath from a SKSpriteNode in SWIFT
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • Generate random number from custom distribution
  • Breaking out column by groups in Pandas
  • wxPython: displaying multiple widgets in same frame
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Mysterious problem with floating point in LISP - time axis generation
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • R - Combining Columns to String Based on Logical Match
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Knitr HTML Loop - Some HTML output, some R output
  • Why winpcap requires both .lib and .dll to run?
  • embed rChart in Markdown
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal