1

I am using the baseline package in R and just working through the documentation. Their example code produces the following image.

data(milk)
bc.irls <- baseline(milk$spectra[1,, drop=FALSE])
plot(bc.irls)

example_spectrum

In my case, the x ticks should not start with 0, but with 5000 (so the annotation of the x axis is off by 5000). Is it possible to change the range in the baseline constructor? Or can I somehow adjust the x labels in the plot method?

Matze
  • 368
  • 1
  • 3
  • 12

1 Answers1

2

According to the docs, baseline is an S4 class with the accessor method getCorrected, which returns a matrix.

In the case of your example, this matrix has a single row and 21,452 columns. You can therefore convert it to a vector and remove the first 4999 elements to get the spectrum starting at 5000. You also need to create a sequence of 5,000 to 21,452 to act as the x axis values. You can then just plot as you would for any other x, y vectors:

new_spec <- as.vector(getCorrected(bc.irls))
new_spec <- new_spec[5000:length(new_spec)]
new_x <- seq_along(new_spec) + 4999
plot(new_x, new_spec, type = "l", main = "Baseline corrected spectrum")

enter image description here

Allan Cameron
  • 147,086
  • 7
  • 49
  • 87