hist distribution using ggplot2

北战南征 提交于 2020-01-07 07:58:10

问题


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

Another example:


回答1:


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:



来源:https://stackoverflow.com/questions/31698858/hist-distribution-using-ggplot2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!