1

I'm using PLS package and was trying to print the loading plot using the follwing code. I've wanted that the X axis to be the wavelength value that is the column names of my df. But it somehow plot the number of column (that is the number of wavelengths) instead of the wavelengths. Appreciate any advice.

> dfq[1,1:5]
    percent 1352.94 1357.53 1361.75 1365.98
1 0.5  0.0548   0.077  0.1015  0.1299
>

> qfit
Partial least squares regression , fitted with the kernel algorithm.
Cross-validated using 150 leave-one-out segments.
Call:
plsr(formula = dfq$percent ~ ., ncomp = 10, data = dfq,     validation     = "LOO")
> 

> plot(qfit, "loadings", comps = 1:3, legendpos = "topright", 
+      xlab = "nm", ylim=c(-0.3,0.85), xlim=c(0,230));
> abline(h=0)
user4178184
  • 89
  • 1
  • 8
  • 1
    You should provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data. If we are unable to copy/paste your code to run it, it is much harder to help you. – MrFlick Feb 23 '16 at 01:51

1 Answers1

0

If I understand the question correctly - that you want wavelength as the x-axis values, rather than index - then add the labels = "numbers" argument to the plot() call. This will prompt the plot function to interpret variable names as numbers. You must hence ensure that the vector elements are each named with the corresponding wavelength value.

See the pls package vignette.

pyg
  • 716
  • 6
  • 18