Why does the x-axis of my plot start at 5 instead of at the lowest point of the vector?

StackOverflow https://stackoverflow.com/questions/9397033

  •  29-10-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top