4

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?

2 Answers 2

15

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.