-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path03_plot-speclibs.Rmd
More file actions
107 lines (88 loc) · 3.42 KB
/
Copy path03_plot-speclibs.Rmd
File metadata and controls
107 lines (88 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: "Part 3: Plotting of Speclibs"
author: "Patrick Schratz"
date: "`r format(Sys.time(), '%a %d %b %Y')`"
output:
html_document:
theme: paper
highlight: haddock
# code_folding: show
toc: yes
toc_depth: 4
toc_float: yes
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE, cache=FALSE}
## knitr options
# knitr::opts_chunk$set(cache = FALSE)
knitr::opts_chunk$set(comment = "")
library("raster")
library("hsdar")
library("here")
library("rasterVis", )
library("mapview")
library("magrittr")
library("stars")
# create objects from previous document
file <- here("data") %>%
list.files(pattern = ".tif$", full.names = TRUE)
raster <- raster::brick(file[1])
wavelength <- c(
404.08, 408.5, 412.92, 417.36,
421.81, 426.27, 430.73, 435.20,
439.69, 444.18, 448.68, 453.18, 457.69, 462.22, 466.75, 471.29,
475.83, 480.39, 484.95, 489.52, 494.09, 498.68, 503.26, 507.86,
512.47, 517.08, 521.70, 526.32, 530.95, 535.58, 540.23, 544.88,
549.54, 554.20, 558.86, 563.54, 568.22, 572.90, 577.60, 582.29,
586.99, 591.70, 596.41, 601.13, 605.85, 610.58, 615.31, 620.05,
624.79, 629.54, 634.29, 639.04, 643.80, 648.56, 653.33, 658.10,
662.88, 667.66, 672.44, 677.23, 682.02, 686.81, 691.60, 696.40,
701.21, 706.01, 710.82, 715.64, 720.45, 725.27, 730.09, 734.91,
739.73, 744.56, 749.39, 754.22, 759.05, 763.89, 768.72, 773.56,
778.40, 783.24, 788.08, 792.93, 797.77, 802.62, 807.47, 812.32,
817.17, 822.02, 826.87, 831.72, 836.57, 841.42, 846.28, 851.13,
855.98, 860.83, 865.69, 870.54, 875.39, 880.24, 885.09, 889.94,
894.79, 899.64, 904.49, 909.34, 914.18, 919.03, 923.87, 928.71,
933.55, 938.39, 943.23, 948.07, 952.90, 957.73, 962.56, 967.39,
972.22, 977.04, 981.87, 986.68, 991.50, 996.31
)
speclib <- hsdar::speclib(raster, wavelength)
mask(speclib) <- c(404, 418)
hyperspecs <- hsdar::HyperSpecRaster(raster, wavelength)
```
Objects of class `Speclib` can be plotted using the generic `plot()` function.
Additional arguments can be specified to produce detailed plots.
# Default `plot()` call
The default `plot()` call plots the mean values including the standard deviation across all spectra in our `speclib`.
```{r 03-plot-speclibs-1 }
plot(speclib)
```
# Plotting of a specific spectrum
We have 28350 (162*175) spectra stored in our `speclib` object.
```{r 03-plot-speclibs-2 }
nspectra(speclib)
```
To plot the 100th spectrum, we can do the following:
```{r 03-plot-speclibs-3 }
plot(speclib, FUN = 100, main = "100th spectrum of Speclib")
```
# Combining multiple spectra
In R the `par()` argument specifies the arrangement of multiple plots using the base `plot()` call.
Let´s combine four different plots in a 2x2 matrix and color the single spectrum
```{r 03-plot-speclibs-4 }
par(mfrow = c(2,2))
plot(speclib, main = "All spectra")
plot(speclib, FUN = 100, main = "100th spectrum of Speclib", col = "cyan")
plot(speclib, FUN = "median", main = "Median spectrum")
plot(speclib, FUN = "mean", main = "Mean spectrum")
```
When combining multiple single spectra, you might want to distinguish them by color. This can be done by appending plots using the argument `new = FALSE`.
This prevents the call of a new plot and appends to the previous one.
Let's take the 1st, the 5th and the 10th spectra.
```{r 03-plot-speclibs-5 }
par(mfrow = c(1,1))
plot(speclib, FUN = 1, col = "red")
plot(speclib, FUN = 5, col = "blue", new = FALSE)
plot(speclib, FUN = 10, col = "orange", new = FALSE)
```