如何绘制直方图,其中删除之间的垂直线?

时间:2016-07-07 18:01:07

标签: r plot histogram

我有一个像

这样的变量的直方图
aa=-(a$mmag)/2.5
hist(10^(aa),breaks=40,xlab=expression(paste(mu)),ylab=NA)

如何在两者之间漫射垂直线?

enter image description here

2 个答案:

答案 0 :(得分:3)

这是我能想到的唯一解决方案:

hist(rnorm(1000), col = "grey", border = "grey")

基本上我们将线条颜色(border)和填充颜色(col)设置为相同。不要尝试设置“白色”;你什么也看不见。

enter image description here

答案 1 :(得分:0)

这是一个应该完成它的功能......随意编辑!

empty_hist <- function(x,...) {
  histo <- hist(x,plot=F)
  plot(NA,xlim=c(min(histo$breaks),max(histo$breaks)),ylim=c(0,max(histo$counts)),xlab="",ylab="count",...=...)
  segments(x0=histo$breaks[1:(length(histo$breaks)-1)],x1=histo$breaks[2:length(histo$breaks)],y0=histo$counts,y1=histo$counts)
  segments(x0=histo$breaks[2:(length(histo$breaks)-1)],x1=histo$breaks[2:(length(histo$breaks)-1)],y0=histo$counts[1:(length(histo$counts)-1)],y1=histo$counts[2:(length(histo$counts))])
  segments(x0=histo$breaks[c(1,length(histo$breaks))],x1=histo$breaks[c(1,length(histo$breaks))],y0=c(0,0),y1=histo$counts[c(1,length(histo$counts))])
  abline(h=0)
}
x <- rnorm(100)
empty_hist(x, main="here's a title")