-1

I am new to statistics and using Rstudio, so I really don't know much about anything :(

As mentioned in the question, I am trying to make a histogram in Rstudio without using the function hist() but using lines() in for loops.

counts =  function(x,n) {

xs = cut(x, breaks=seq(min(x),max(x), length.out = n+1), right = FALSE)
ys = as.vector(table(xs))
}
return(ys)
}

So the above is the function that will create intervals of a vector x, and I have to create another function called histo() that will build the histogram without using hist().

I have tried using abline(), but that didn't work. Any suggestions please?

camille
  • 16,432
  • 18
  • 38
  • 60
  • Do you have to use `lines`? `segments` is probably the more appropriate vectorised solution for drawing a series of straight lines. – thelatemail Feb 12 '20 at 00:17
  • 3
    Why can't you use `hist`? – camille Feb 12 '20 at 00:20
  • @camille it is a requirement in my assignment I don't understand why either. – staymydear Feb 12 '20 at 00:26
  • @thelatemail I guess so as our class hasn't learned anything about segments but wee went over on using lines :( – staymydear Feb 12 '20 at 00:28
  • 2
    I'm sorry but this isn't really the right place for general homework help. Teachers seem to love coming up with assignments that aren't practically useful. When asking a question here it helps if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Stack Overflow expected people to posts answers to a question, not suggestions, so try to make it easy to do that. – MrFlick Feb 12 '20 at 00:33
  • 1
    @staymydear - you could argue that you are very smart and read `?plot` - which would also point you to `plot(counts(x,10), type="h")` which does a histogram-like plot using lines. – thelatemail Feb 12 '20 at 00:34
  • how about `?rect` ? – Ben Bolker Feb 12 '20 at 02:00

1 Answers1

-1

Would using geom_histogram() from the ggplot2 package work for you? It doesn't require hist() Sorry can't comment yet due to rep

David
  • 23
  • 9