Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to vary binwidth inside ggplot?

I'am doing histogram with ggplot.

p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) + 
    xlab(xlabel) + ylab(ylabel) +
    geom_histogram(colour = "darkblue", fill = "white", binwidth=500)

my x is between 2 and 6580 and I have 2600 data.

I want to plot one histogram with different binwidth. Is it possible?

For example, I want to have 8 bars, with width like this:

c(180,100,110,160,200,250,1000,3000)

How can I do it?

like image 785
Tali Avatar asked Dec 03 '22 06:12

Tali


1 Answers

how about using breaks?

x <- rnorm(100)
ggplot(NULL, aes(x)) + 
  geom_histogram(breaks = c(-5, -2, 0, 5), 
  position = "identity", colour = "black", fill = "white")

P.S. Please don't cross post without explicit notification.

enter image description here

like image 164
kohske Avatar answered Dec 12 '22 13:12

kohske