This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.
title: “Spatial patterns in Pinus pinea regeneration transects” output: html_notebook — [Notebook details: This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code. Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter. ]
stored in GoogleSheet ‘gsn’, worksheet name ‘wsn’ archived 2/1/2017 https://www.zenodo.org/deposit/228327
library(googlesheets)
suppressMessages(library(dplyr))
gsn <-"TransectPinusPinea" # GoogleSheetName
gs_ls(gsn)
## # A tibble: 2 x 10
## sheet_title author perm version updated
## <chr> <chr> <chr> <chr> <dttm>
## 1 TransectPinusPinea scotti rw old 2017-05-30 15:29:19
## 2 TransectPinusPinea_v2 scotti rw old 2016-12-09 10:33:58
## # ... with 5 more variables: sheet_key <chr>, ws_feed <chr>,
## # alternate <chr>, self <chr>, alt_key <chr>
tpp <- gs_title(gsn)
wsn <- "PointPatternWithMarks" # WorkSheetName
cat("Sheet '", wsn, "'", ifelse(wsn %in% gs_ws_ls(tpp),"", "NOT "), "found.")
## Sheet ' PointPatternWithMarks ' found.
ppwm <- tpp %>% gs_read(ws=wsn)
ppwm$nPf <- as.factor(ppwm$`N palchi`)
str(ppwm)
## Classes 'tbl_df', 'tbl' and 'data.frame': 102 obs. of 15 variables:
## $ Area : chr "3" "3" "3" "3" ...
## $ IdPoint : chr "C1" "C2" "C3" "C4" ...
## $ X : num 5.4 14.6 23 26.1 26.8 29.2 26.6 29.2 32.4 33.3 ...
## $ Y : num 9.3 4.8 5.5 9.9 4.3 4 4.4 4.4 0.7 4.3 ...
## $ H [m] : num 7.5 2.4 6 3.6 3.4 6.7 3.6 3.2 3.3 8 ...
## $ N palchi : int 13 8 10 8 7 11 8 9 6 13 ...
## $ AreaInsid : num 63.65 4.95 23.01 4.81 2.88 ...
## $ Note : chr NA NA NA NA ...
## $ Note_cod : chr "A" "A" "A" "A" ...
## $ KEY : chr "3C1" "3C2" "3C3" "3C4" ...
## $ n_el_gruppo : int 1 1 1 1 1 1 2 1 1 1 ...
## $ sum_d_coll_sq: int 7396 169 1600 100 49 1600 148 169 36 1444 ...
## $ n_fusti : int 3 1 3 1 1 2 2 1 1 2 ...
## $ sum_d130sq : int 1785 9 509 49 16 845 49 25 4 1025 ...
## $ nPf : Factor w/ 13 levels "2","3","4","5",..: 12 7 9 7 6 10 7 8 5 12 ...
## - attr(*, "spec")=List of 2
## ..$ cols :List of 14
## .. ..$ Area : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## .. ..$ IdPoint : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## .. ..$ X : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Y : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ H [m] : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ N palchi : list()
## .. .. ..- attr(*, "class")= chr "collector_integer" "collector"
## .. ..$ AreaInsid : list()
## .. .. ..- attr(*, "class")= chr "collector_double" "collector"
## .. ..$ Note : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## .. ..$ Note_cod : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## .. ..$ KEY : list()
## .. .. ..- attr(*, "class")= chr "collector_character" "collector"
## .. ..$ n_el_gruppo : list()
## .. .. ..- attr(*, "class")= chr "collector_integer" "collector"
## .. ..$ sum_d_coll_sq: list()
## .. .. ..- attr(*, "class")= chr "collector_integer" "collector"
## .. ..$ n_fusti : list()
## .. .. ..- attr(*, "class")= chr "collector_integer" "collector"
## .. ..$ sum_d130sq : list()
## .. .. ..- attr(*, "class")= chr "collector_integer" "collector"
## ..$ default: list()
## .. ..- attr(*, "class")= chr "collector_guess" "collector"
## ..- attr(*, "class")= chr "col_spec"
Some positions are occupied by a single stem, some correspond to stem bunches. Some attributes can hence have more than one value. These have been aggregated in the worksheet as counts and sums or averages.
Spatial patterns windows are, partially, undefined. The width is fixed to 10m while the length is open and has to be estimated!!
library(spatstat)
## Loading required package: nlme
##
## Attaching package: 'nlme'
## The following object is masked from 'package:dplyr':
##
## collapse
## Loading required package: rpart
##
## spatstat 1.51-0 (nickname: 'Poetic Licence')
## For an introduction to spatstat, type 'beginner'
Areas <- unique(ppwm$Area)
t_windows <- list()
for(tid in Areas) t_windows[[tid]] <- ripras(ppwm$X[ppwm$Area==tid],ppwm$Y[ppwm$Area==tid], shape = "rectangle")
# ripras(): Estimate window from points alone
trss <- solist ()
# to display transect as seen from the see
# exchange x and y
# reflect on the negative side the y ==> k=-1
K <- -1
for(tid in Areas) {
trs <- ppp(ppwm$Y[ppwm$Area==tid],K*c(ppwm$X[ppwm$Area==tid])
, yrange = range(K*t_windows[[tid]]$xrange), xrange = c(-10, 10)
, marks = ppwm[ppwm$Area==tid, c(5:7, 9, 11:15)])
unitname(trs) <- "m"
# print(paste(tid,class(trs)))
trss[[length(trss)+1]] <- trs
}
names(trss)=paste("Trs-",Areas,sep="")
trssum <- as.solist(lapply(trss, unmark))
summary(trssum)
## Summary of 4 point patterns
##
## Trs-3:
## Planar point pattern: 27 points
## Average intensity 0.01971024 points per square m
##
## Coordinates are given to 1 decimal place
## i.e. rounded to the nearest multiple of 0.1 m
##
## Window: rectangle = [-10, 10] x [-71.44615, -2.95385] m
## Window area = 1369.85 square m
## Unit of length: 1 m
##
## Trs-4:
## Planar point pattern: 37 points
## Average intensity 0.0367428 points per square m
##
## Coordinates are given to 1 decimal place
## i.e. rounded to the nearest multiple of 0.1 m
##
## Window: rectangle = [-10, 10] x [-51.825, -1.475] m
## Window area = 1007 square m
## Unit of length: 1 m
##
## Trs-5:
## Planar point pattern: 25 points
## Average intensity 0.02465483 points per square m
##
## Coordinates are given to 2 decimal places
## i.e. rounded to the nearest multiple of 0.01 m
##
## Window: rectangle = [-10, 10] x [-55.25, -4.55] m
## Window area = 1014 square m
## Unit of length: 1 m
##
## Trs-6-7:
## Planar point pattern: 13 points
## Average intensity 0.01714286 points per square m
##
## Coordinates are given to 2 decimal places
## i.e. rounded to the nearest multiple of 0.01 m
##
## Window: rectangle = [-10, 10] x [-43.00833, -5.09167] m
## Window area = 758.333 square m
## Unit of length: 1 m
plot(trssum, nrows=1, equal.scales=T, valign=T, main = "", hsep=4, cex.main=.7)
Axis(trss, side=4, cex.axis=.6, at=seq(100,20,-20), labels = seq(0,80,20))
title(main="Transetti", line = 0)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).