|
3 | 3 | #' Use segmented regression to create a speciation-area relationship plot. The |
4 | 4 | #' X axis represents log(island area) and the Y axis represents |
5 | 5 | #' log(speciation rate) |
6 | | -#' |
7 | | -#' If the user would prefer to create their own plot of the |
| 6 | +#' |
| 7 | +#' If the user would prefer to create their own plot of the |
8 | 8 | #' `ssarp::create_SpAR()` output, the `aggDF` element of the returned list |
9 | 9 | #' includes the raw points from the plot created here. They can be accessed |
10 | 10 | #' as demonstrated in the Examples section. |
| 11 | +#' |
| 12 | +#' More information about the three methods for estimating speciation rate |
| 13 | +#' included in `ssarp` can be found in [ssarp's SpAR vignette](https://kmartinet.github.io/ssarp/articles/Create_SpAR.html). |
11 | 14 | #' @param occurrences The dataframe output by one of ssarp's speciation |
12 | 15 | #' methods (`ssarp::estimate_BAMM()`, `ssarp::estimate_DR()`, |
13 | 16 | #' `ssarp::estimate_MS()`), or if using a custom dataframe, ensure that it |
14 | 17 | #' has the following columns: areas, rate |
15 | 18 | #' @param npsi The maximum number of breakpoints to estimate for model |
16 | 19 | #' selection. Default: 1 |
17 | | -#' @param visualize (boolean) Whether the plot should be displayed when the |
| 20 | +#' @param visualize (boolean) Whether the plot should be displayed when the |
18 | 21 | #' function is called. Default: FALSE |
19 | 22 | #' @return A list of 4 including: the summary output, the regression |
20 | 23 | #' object, the aggregated dataframe used to create the plot, and the AIC scores |
21 | 24 | #' used in model selection |
22 | 25 | #' @examples |
23 | 26 | #' # The GBIF key for the Anolis genus is 8782549 |
24 | 27 | #' # Read in example dataset filtered from: |
25 | | -#' # dat <- rgbif::occ_search(taxonKey = 8782549, |
| 28 | +#' # dat <- rgbif::occ_search(taxonKey = 8782549, |
26 | 29 | #' # hasCoordinate = TRUE, |
27 | 30 | #' # limit = 10000) |
28 | 31 | #' dat <- read.csv(system.file("extdata", |
29 | 32 | #' "ssarp_Example_Dat.csv", |
30 | 33 | #' package = "ssarp")) |
31 | 34 | #' land <- find_land(occurrences = dat) |
32 | 35 | #' areas <- find_areas(occs = land) |
33 | | -#' |
| 36 | +#' |
34 | 37 | #' # Read tree from Patton et al. (2021), trimmed to Caribbean species |
35 | 38 | #' tree <- ape::read.tree(system.file("extdata", |
36 | 39 | #' "Patton_Anolis_trimmed.tree", |
|
39 | 42 | #' occ_speciation <- estimate_MS(tree = tree, |
40 | 43 | #' label_type = "epithet", |
41 | 44 | #' occurrences = areas) |
42 | | -#' |
43 | | -#' seg <- create_SpAR(occurrences = occ_speciation, |
| 45 | +#' |
| 46 | +#' seg <- create_SpAR(occurrences = occ_speciation, |
44 | 47 | #' npsi = 1, |
45 | 48 | #' visualize = FALSE) |
46 | 49 | #' plot(seg) |
@@ -122,7 +125,7 @@ create_SpAR <- function(occurrences, npsi = 1, visualize = FALSE) { |
122 | 125 |
|
123 | 126 | # If the min_score is index 1, then the best-fit model is linear |
124 | 127 | if (min_score == 1) { |
125 | | - if(visualize){ |
| 128 | + if (visualize) { |
126 | 129 | plot( |
127 | 130 | dat, |
128 | 131 | xlim = c(x_min, (x_max + 0.5)), |
@@ -161,7 +164,7 @@ create_SpAR <- function(occurrences, npsi = 1, visualize = FALSE) { |
161 | 164 | ) |
162 | 165 |
|
163 | 166 | # Plot the breakpoint regression line |
164 | | - if(visualize){ |
| 167 | + if (visualize) { |
165 | 168 | plot( |
166 | 169 | seg, |
167 | 170 | rug = FALSE, |
@@ -204,7 +207,7 @@ create_SpAR <- function(occurrences, npsi = 1, visualize = FALSE) { |
204 | 207 |
|
205 | 208 | # Plot defaults to multiple outputs when npsi > 1, so my npsi = 1 plot |
206 | 209 | # doesn't apply |
207 | | - if(visualize){ |
| 210 | + if (visualize) { |
208 | 211 | plot(seg) |
209 | 212 | } |
210 | 213 |
|
|
0 commit comments