To compute Numerical Summaries for the cells of each layer we can use:
...
Below examples of the computation of numerical summaries for raster layers in R are presented. These examples are taken from the “Effects of Cyclone Yasi on Green Cover at Mission Beach” tutorial. It can be beneficial to put the code snippets in context by looking at a broader section of the R script. Code snippets have a grey background, and outputs have a white background.
Boxes with grey background contain code snippets, and boxes with white background containt code (text) outputs
Multiple numerical summary statistics using the function ‘summary’ from the ‘base’ package
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
summary(SPGC.StudyArea.2010q3_2011q3.rb)
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## SPGC_2010q3 SPGC_2011q3
## Min. 39.21569 39.21569
## 1st Qu. 67.05882 67.84314
## Median 68.62745 69.41176
## 3rd Qu. 70.19608 70.58824
## Max. 77.25490 76.86275
## NA's 0.00000 0.00000
|
.
.
.
Individual summary statistics using the function ‘cellStats’ from the ‘raster’ package
.
RasterLayer object
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
cellStats(SPGC.StudyArea.2010q3.rl, mean)
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## [1] 68.12031
|
.
.
RasterBrick object
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
cellStats(SPGC.StudyArea.2010q3_2011q3.rb, mean)
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## SPGC.SA.2010q3 SPGC.SA.2011q3
## 68.12031 68.81528
|
.
.
.
Individual summary statistics using statistical functions from the ‘base’ package (e.g. ‘mean’, ‘sd’)
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
|
.
.
RasterLayer object
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
mean(values(SPGC.StudyArea.2010q3.rl))
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## [1] 68.12031
|
.
.
RasterBrick object
Applying the ‘mean’ function on a Multi-Layer Raster object summarises the values in all the layers into a single value. This behaviour is different that obtained using the ‘cellStats’ function with the argument ‘mean’, which returned a summary value for each layer (see above).
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
mean(values(SPGC.StudyArea.2010q3_2011q3.rb))
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
## [1] 68.46779
|
.
.
Div |
---|
style | background-color: #F8F9F9; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
mean(cellStats(SPGC.StudyArea.2010q3_2011q3.rb, mean))
|
.
Div |
---|
style | background-color: white; border: 1px solid #666; font-size: 12px; padding: 0.5rem 0.5rem; |
---|
|
|
.
.
.