Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

r - hist distribution using ggplot2

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...