在ggplot2直方图中设置中断 [英] setting breaks in ggplot2 histogram
本文介绍了在ggplot2直方图中设置中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
values = rnorm(100)
plot = ggplot(data.frame(val = value),aes(x = val))+ geom_histogram(aes(y = ..density ..))+ geom_density()
然而,我需要用不同的中断点打印几张图(不是一张不同的小图),比如说:
breaks = list(c(-1,0,1),c(-2,-1.5,0,1.5,2),c(-0.5,0,0.5))
如何重新定义变量 plot
?
解决方案
使用您自己的代码,您可以这样做:
ggplot(data.frame(val = values),aes(x = val))+
geom_histogram(aes(y = ..density ..))+
geom_density( )+
scale_y_continuous(breaks = c(-2,-1.5,0,1.5,2))
I need to make several histograms regarding the same vector of values and a density estimation. So the next plot is good.
values = rnorm(100)
plot = ggplot(data.frame(val=values), aes(x=val)) + geom_histogram(aes(y = ..density..)) + geom_density()
However, I need to print several plots (not one plot with different panels) with different break points, say:
breaks = list(c(-1,0,1),c(-2,-1.5,0,1.5,2),c(-0.5,0,0.5))
How can I redefine the breaks for the variable plot
?
解决方案
Using your own code, you can do that with:
ggplot(data.frame(val=values), aes(x=val)) +
geom_histogram(aes(y = ..density..)) +
geom_density() +
scale_y_continuous(breaks=c(-2,-1.5,0,1.5,2))
这篇关于在ggplot2直方图中设置中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文