Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change bin width on R highcharter histogram

Tags:

r

highcharts

In the basic example of the histogram generated by R highcharter package that is:

hchart(diamonds$price)

the bin width is automatically set to 200. I tried few datasets and the bin width vary. That makes me think that this is somehow set automatically. How can I set it manually?

like image 555
Mikolaj Avatar asked Jan 04 '23 22:01

Mikolaj


1 Answers

hchartis a generic function which work with histogram classes too. Try following:

library(highcharter)
data(diamonds, package = "ggplot2")

h <- hist(diamonds$price, plot = FALSE)
hchart(h)


h2 <- hist(diamonds$price, breaks = 100, plot = FALSE)
hchart(h2)

So, you can create the histogram what you want using the base hist function, then you can chart it with highcharter.

like image 167
jbkunst Avatar answered Jan 12 '23 13:01

jbkunst