plot returns discontinuous lines (with gaps) in R when using spectacles package

473 Views Asked by At

UPDATE ABOUT SOLUTION:
set argument gaps = F in your plot() command
library(spectacles) spectra(your_data) <- sr_no ~ ... ~ 350:2500 # turn your data frame to Spectra* object with the spectrum range of your interest plot(your_data, gaps = F) # return plot with no gaps or line discontinuously

#

I have to work with a Spectra* object and plot with the code as similar as this, just changing buil-in "australia" data frame by my data:

library(spectacles)    
data(australia)     
spectra(australia) <- sr_no ~ ... ~ 350:2500    
s <- cut(australia, wl =c(-1*450:500, -1*1800:2050))    
plot(s)    

My plot in R returned discontinuously as the attached image below. Data frame's dimension is 150 rows, 3156 columns. The problem remains when I reduced df to 1800 columns.

Has anyone had the same problems? Could you suggest a solution? Thank you so much in advance!

Plotting wavenumber vs abs value

1

There are 1 best solutions below

1
On

Please bear with me as it is a lot easier to explain my question by visualization than to leave a comment. Do you want to remove this data or are you wanting to cut a portion of the data? See examples below.

s1 <- cut(australia, wl =c(-1*450:500, -1*1800:2050))
plot(s, gap=TRUE)

Spectral minus 450:500 & 1800:2050

Alternatively you could use the example for the help file in R.

library(ggplot)
data(australia)
spectra(australia) <- id ~ ... ~ 500:1800 # changed the range

r <- melt_spectra(australia)
australia$fact <- sample(LETTERS[1:3], size = nrow(australia), replace = TRUE)
r <- melt_spectra(australia, attr = 'fact')
p <- ggplot(r) + geom_line(aes(x=wl, y=nir, group=id, colour=fact)) + theme_bw()
print(p)

Spectral image from 500:1800

Alternative you can take a portion of the analysis.

s <- as(cut(australia, wl = 1*450:550), 'Spectra') 
plot(s)

subset of spectra