How to fix number of bins in histogram using R

r
histogram

#1

I am using hist function to plot the data I want to plot only the first 4 bins and suppress the remaining one because the are almost are getting to negligible so I want to remove it .
z<-mtcars
hist(z$hp)


#2

R chooses how to bin your data for you by default using an algorithm, but if you want coarser or finer groups, there are a number of ways to do this. An easy way is just to give it one number that gives the number of cells for the histogram:

hist(data, breaks=20)
hist(data, breaks=5)

or you can provide a vector of break-points and mention the exact points at which you need the break:

hist(data, breaks=c(17,20,23,26,29,32))


#3

Sid,
I think this is what you want to do:

mtcar.small=subset(mtcars,hp<250)
hist(mtcar.small$hp)

Hope this helps.
To limit the # of rows, you can use any other convenient value in place of 250.