@@ -18,7 +18,8 @@ f.plot.spec <- function(
1818 xlim = NULL , # # vector to change the default xlim of the plots (ex xlim = c(500, 2400))
1919 position = ' topright' ,# # Position of the legend (see base function legend for help)
2020 type = ' Reflectance' , # # Name of the y axis and of the legend
21- plot_label = NULL # # optional label for plot
21+ plot_label = NULL , # # optional label for plot
22+ CI = 95 # # confidence interval, default 95% ; can also be 90%
2223){
2324 if (mean(as.matrix(Z ),na.rm = TRUE )> 1 ){Z = Z / 100 } # # Check if the spectra are in pc [0,100] or in [0,1]
2425 if (is.null(xlim )){xlim = c(min(wv ),max(wv ))}
@@ -27,12 +28,23 @@ f.plot.spec <- function(
2728
2829 plot(x = NULL ,y = NULL ,ylim = c(0 ,100 ),xlim = xlim ,xlab = " Wavelength (nm)" ,
2930 ylab = paste0(type ," (%)" ),main = plot_label )
31+
32+ if (CI == 95 ){
33+ ci_text = " 95% CI"
34+ polygon(c(wv ,rev(wv )),c(spectra_quantiles [6 ,]* 100 , rev(spectra_quantiles [2 ,]* 100 )),
35+ col = " #99CC99" ,border = NA )
36+ }
37+
38+ if (CI == 90 ){
39+ ci_text = " 90% CI"
3040 polygon(c(wv ,rev(wv )),c(spectra_quantiles [5 ,]* 100 , rev(spectra_quantiles [3 ,]* 100 )),
3141 col = " #99CC99" ,border = NA )
42+ }
43+
3244 lines(wv ,mean_spec * 100 ,lwd = 2 , lty = 1 , col = " black" )
3345 lines(wv ,spectra_quantiles [1 ,]* 100 , lty = 3 , col = " grey40" )
3446 lines(wv ,spectra_quantiles [7 ,]* 100 , lty = 3 , col = " grey40" )
35- legend(position ,legend = c(paste(" Mean" ,type )," Min/Max" , " 95% CI " ),lty = c(1 ,3 ,1 ),
47+ legend(position ,legend = c(paste(" Mean" ,type )," Min/Max" , ci_text ),lty = c(1 ,3 ,1 ),
3648 lwd = c(2 ,1 ,10 ),col = c(" black" ," grey40" ," #99CC99" ),bty = " n" )
3749 box(lwd = 2.2 )
3850}
0 commit comments