Reputation: 741
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?
Upvotes: 4
Views: 7654
Reputation: 66874
Use breaks
and position="dodge"
eg:
ggplot(mtcars,aes(x=hp))+geom_histogram(breaks=c(50,100,200,350),position="dodge")
Don't have your data, but for your example:
p <- ggplot(TotCalc, aes(x=x,y=100*(..count../sum(..count..)))) +
xlab(xlabel) + ylab(ylabel) +
geom_histogram(colour = "darkblue", fill = "white", breaks=cumsum(c(180,100,110,160,200,250,1000,3000)), position="dodge")
Upvotes: 2
Reputation: 66902
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.
Upvotes: 15