Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
下面绘制了一个直方图,其最左边的点为 0。
myplot = ggplot(df,aes(x = myvar)) + geom_histogram(aes(y = ..density..), binwidth = .3)
我希望直方图有一个以 0 为中心的 bin。(如果你想知道为什么我想做这么古怪的事情 - 这是为了说明直方图的一些弱点。)
您可以将breaks参数传递stat_bin给..., (geom_histogram调用stat_bin)
breaks
stat_bin
...
geom_histogram
myplot <- ggplot(df,aes(x = myvar))+ geom_histogram(aes(y = ..density..), breaks = seq(0,5,by=1))
这覆盖bindwidth和origin
bindwidth
origin
有关更多详细信息,请参阅 stat_bin 的帮助。
您可能还会发现origin一个有用的参数(origin = 0可能是设置),但不能与breaks!
origin = 0