0

I have a histogram of a variable like

aa=-(a$mmag)/2.5
hist(10^(aa),breaks=40,xlab=expression(paste(mu)),ylab=NA)

How to diffuse the vertical lines in between ?

enter image description here

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Ayan Mitra
  • 497
  • 1
  • 8
  • 20
  • I believe `hist` doesn't have any option to do this. You'll likely need to generate your own function to mimic that capability. (By "*diffuse*" I infer you mean "completely remove"). – r2evans Jul 07 '16 at 18:08
  • Please make a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) . Exactly what lines are you talking about? – MrFlick Jul 07 '16 at 18:09
  • Sorry for the confusion....The vertical lines between each bar – Ayan Mitra Jul 07 '16 at 18:10
  • (By the way, you "accept" answers by clicking on the checkmark to the left of an answer. It's a courtesy here on SO, and giving the answerer the credit and reputation points for doing so is a little payback for the time spent.) – r2evans Jul 07 '16 at 18:11
  • I dont get your point @r2evans... doesn't people give you acceptance for your answers ? You haven't given an answer anyways, here. Sorry I feel you are rude for no reason. – Ayan Mitra Jul 07 '16 at 18:14
  • 1
    I'm commenting on the 6 other questions you've asked and yet you've only accepted 2. I'm not trying to be mean, though I know it comes across as that. A common habit (*I think*) among some SO answerers is to see how much effort you've put in, both to the specific questions and questions in the past. In your case, you've answered 2 but left 4 unanswered, so I'm giving a slight nudge to either accept an answer (even if your own) or comment on why they don't work. – r2evans Jul 07 '16 at 18:18
  • I dont think I have even made 6 questions..maybe you are mixing with someone else ? – Ayan Mitra Jul 07 '16 at 18:20
  • 1
    You've made 7 with this one. You can click on your username to see your profile, including questions asked. – r2evans Jul 07 '16 at 18:25
  • You are burning for no reason... :) cool down...I have no enmity against you..a simple reminder would have done...but this just goes to show your immaturity ....whoever answers me I am always thankful to them...but if you feel you are undone..report to stackoverflow or LEAVE! instead of being rude. – Ayan Mitra Jul 07 '16 at 18:45

2 Answers2

3

This is the only solution I could think of:

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

Basically we set line colour (border) and filled colour (col) to be the same. Don't try setting "white"; you see nothing from that.

enter image description here

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
0

Here's a function that should accomplish it... feel free to edit at will!

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")
Matt Tyers
  • 2,125
  • 1
  • 14
  • 23
  • @ZheyuanLi Sorry, didn't mean to give the impression that I had stolen your idea. Truth be told, I didn't see your comment until after I had posted with my solution, which I admit is very similar to yours! Please keep in mind that `hist()` and `segments()` are fairly commonly-used functions, and it's not uncommon for researchers to reach the same results independently. I'll upvote your solution in a gesture of goodwill though. – Matt Tyers Jul 07 '16 at 19:07