Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I plot a vector distribution with qplot that I don't know its distribution in advance, it's calculated in a function. I just know that the x values are between 0 and 1.

I use the below command line and get the attached histogram.

As the distribution is jammed, how can I make it more spread so that the distribution becomes clear? which parameters to use or other functions that produce histogram?

Moreover how to color so that the bins becomes more distiguishable?

keeping the color legend may or may not be necessary.

qplot(my.vec,binwidth = .2)+ 
  geom_histogram(binwidth = .2, aes(fill = ..count..), colour='black', fill='skyblue')

enter image description here

Another example: enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
156 views
Welcome To Ask or Share your Answers For Others

1 Answer

To "unjam" the plot, use xlim:

qplot(x) + geom_histogram(binwidth = 0.2, aes(fill = ..count..), colour='black', fill='skyblue') + xlim(0,1)

I'm not sure why you want to use variation in color here when column height is already giving you that information. That's the whole point of a histogram, and then you don't have to worry about confusing color-blind people. So why not just:

qplot(x) + geom_histogram(binwidth = 0.2, colour='black', fill='skyblue') + xlim(0,1)

Here's the toy data I used to test it:

x <- c(0.41, 0.42, 0.47, 0.47, 0.49, 0.50, 0.51, 0.55, 0.56, 0.57, 0.59, 0.61, 0.62, 0.65, 0.68, 0.69, 0.70, 0.75, 0.78, 0.79)

And here's a .png of the plot I got:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...