1

I'm trying to make a histogram of a vector using R. When I plot this the x-axis goes from 5 to 9 but part of the histogram is before 5 (the lowest number is 4.414002) and part of it is after 9. The same goes for my y-axis, it goes from 0-5000, but the talles 'stave' goes a bit above this 5000.

Why does it not start at the lowest value in the vector? Mind you, it's only the bar that's not long enough, the graph is the right size (so it's not a problem with mar or oma settings, I tried changing those but that didn't help)

Below is my code

import rpy2.robjects as R
import R_functions as R_funct


csvData = (R.r['read.csv'](file='/homes/ndeklein/test.csv', head=True, sep='\t'))

hist = R.r.hist
R.r.png('/homes/ndeklein/test_intensity_hist.png', width=300, height=300)
intensityVector = csvData[0]
logIntensityVector = R.r['log10'](intensityVector)

hist(logIntensityVector, main='Intensity per feature histogram', xlab='logged intensity', ylab='frequencies of features', br=20)

R.r['dev.off']()

Edit:

I found out what the problem is and in R code it would look like this:

vector = c(5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 5.67750749154535, 6.7399637450174, 6.7399637450174, 6.7399637450174, 6.7399637450174, 6.7399637450174, 6.7399637450174, 6.7399637450174, 6.7399637450174)
hist(vector, breaks=20)

But because the range is between 4-9 (well, less in this example), having 20 breaks was way too much. Putting the breaks on 6 solves the problem.

Niek de Klein
  • 8,524
  • 20
  • 72
  • 143
  • 2
    Can you make your example reproducible, perhaps by using `set.seed` and `runif` to make a data set in one line? – Aaron left Stack Overflow Feb 22 '12 at 16:04
  • 1
    It's going to be very difficult for anyone to answer this, as your example is not [reproducible](http://stackoverflow.com/q/5963269/324364). – joran Feb 22 '12 at 16:09

1 Answers1

0

Putting the breaks on a lower number (br = 6 in my example)

hist(logIntensityVector, main='Intensity per feature histogram', xlab='logged intensity', ylab='frequencies of features', br=6)

solved the problem.

Niek de Klein
  • 8,524
  • 20
  • 72
  • 143