Skip to content

Commit

Permalink
Merge pull request #32 from MindTheGap-ERC/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
NiklasHohmann authored Jul 14, 2024
2 parents 9bd4ddb + 52ee9cd commit 61bd4e6
Show file tree
Hide file tree
Showing 21 changed files with 201 additions and 27 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ S3method(set_T_unit,adm)
S3method(set_T_unit,multiadm)
S3method(set_T_unit,sac)
S3method(strat_to_time,list)
S3method(strat_to_time,numeric)
S3method(strat_to_time,phylo)
S3method(summary,adm)
S3method(summary,multiadm)
S3method(time_to_strat,list)
S3method(time_to_strat,numeric)
S3method(time_to_strat,phylo)
export(L_axis_lab)
export(T_axis_lab)
Expand Down
2 changes: 1 addition & 1 deletion R/adm_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ mean_adm = function(x, h){
for ( i in seq_along(h)){
h_t[[i]] = sapply(h_list, function(x) x[i])
}
t = sapply(h_t, function(x) base::mean(x))
t = sapply(h_t, function(x) base::mean(x, na.rm = TRUE))
adm = tp_to_adm(t = t, h = h, T_unit = get_T_unit(x), L_unit = get_L_unit(x))
return(adm)
}
38 changes: 25 additions & 13 deletions R/plot.multiadm.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ plot.multiadm = function(x, ...){
#'
#' @returns a plot of the multiadm object
#'
#' @description
#' plots the median age (red) and the 95 % envelope (blue) of a multiadm object
#'
#'
#' @examples
#' \dontrun{
#' # see
#' vignette("adm_from_trace_cont")
#' # and
#' vignette("adm_from_sedrate")
#' # for example plots.
#' }
#'



Expand Down Expand Up @@ -47,10 +60,10 @@ move_multiadm_to_env = function(x, ...){
multiadm = x

no_of_entries = multiadm$no_of_entries
t_min = min(sapply(seq_len(no_of_entries), function(x) min(multiadm[["t"]][[x]])))
t_max = max(sapply(seq_len(no_of_entries), function(x) max(multiadm[["t"]][[x]])))
h_min = min(sapply(seq_len(no_of_entries), function(x) min(multiadm[["h"]][[x]])))
h_max = max(sapply(seq_len(no_of_entries), function(x) max(multiadm[["h"]][[x]])))
t_min = min(sapply(seq_len(no_of_entries), function(x) min(multiadm[["t"]][[x]])), na.rm = TRUE)
t_max = max(sapply(seq_len(no_of_entries), function(x) max(multiadm[["t"]][[x]])), na.rm = TRUE)
h_min = min(sapply(seq_len(no_of_entries), function(x) min(multiadm[["h"]][[x]])), na.rm = TRUE)
h_max = max(sapply(seq_len(no_of_entries), function(x) max(multiadm[["h"]][[x]])), na.rm = TRUE)

assign(x = "adm_plot_info",
value = list("T_unit" = x$T_unit,
Expand All @@ -59,7 +72,7 @@ move_multiadm_to_env = function(x, ...){
"t_range" = c(t_min, t_max),
"median_col" = "red",
"envelope_col" = "blue",
"p_envelope" = 0.9,
"p_envelope" = 0.95,
"madm" = x),
envir = .adm_plot_env)
return(invisible())
Expand All @@ -81,14 +94,13 @@ plot_envelope = function(){
multiadm = list$madm

h = seq(list$h_range[1], list$h_range[2], length.out = 100)
h_list = get_time(multiadm, h)
h_t= list()
for ( i in seq_len(100)){
h_t[[i]] = sapply(h_list, function(x) x[i])
}
graphics::lines(sapply(h_t, function(x) stats::quantile(x, 0.5 * (1 - list$p_envelope) , na.rm = TRUE)),h, col = list$envelope_col)
graphics::lines(sapply(h_t, function(x) stats::quantile(x, 0.5 * (1 - list$p_envelope) + list$p_envelope, na.rm = TRUE)),h, col = list$envelope_col)
graphics::lines(sapply(h_t, function(x) stats::quantile(x, 0.5, na.rm = TRUE)),h, col = list$median_col)

q1 = quantile_adm(multiadm, h, 0.025)
q2 = quantile_adm(multiadm, h, 0.975)
me = median_adm(multiadm, h)
graphics::lines(q1$t, q1$h, col = list$envelope_col)
graphics::lines(q2$t, q2$h, col = list$envelope_col)
graphics::lines(me$t, me$h, col = list$median_col)

return(invisible())
}
Expand Down
4 changes: 2 additions & 2 deletions R/strat_to_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ strat_to_time = function(obj, x, ...){
#'
#' @description
#' Takes an object and transforms it from the time domain into the stratigraphic domain using the provided age-depth model.
#' Currently implemented for the "phylo" class.
#' Currently implemented for the "phylo", "list", and "numeric" class. Wraps around `get_time`.
#'
#'
#' @param obj the object to be transformed
Expand All @@ -16,7 +16,7 @@ strat_to_time = function(obj, x, ...){
#'
#' @returns an object of the same type as obj
#'
#' @seealso [time_to_strat()] to transform data from the time to the stratigraphic domain, [strat_to_time.phylo()] and [strat_to_time.list()] for details on how to transform phylo objects and lists
#' @seealso [time_to_strat()] to transform data from the time to the stratigraphic domain, [strat_to_time.phylo()], [strat_to_time.numeric()] and [strat_to_time.list()] for details on how to transform phylogenetic trees, vectors, and lists. See [get_time()] for the underlying procedure.
#'

UseMethod("strat_to_time")
Expand Down
28 changes: 28 additions & 0 deletions R/strat_to_time.numeric.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
strat_to_time.numeric = function(obj, x, ...){

#'
#' @export
#'
#' @title transform numeric vectors from height to time domain
#'
#' @description
#' This function transforms numeric vectors from the stratigrahpic to the time domain
#' Fundamentally a wrapper around get_time for consistent syntax
#'
#'
#' @param obj a numeric vector representing stratigraphic positions.
#' @param x an _adm_ object
#' @param ... options passed to `get_time`
#'
#' @seealso [time_to_strat.numeric()] for the transformation from time to height domain, [get_time()] for the underlying procedure, [time_to_strat()] for the higher level function, [strat_to_time.list()] and [strat_to_time.phylo()] for the transformation of lists and phylogenetic trees.
#'
#' @returns A numeric vector with times of deposition of the entries in `obj`
#'
#' @examples
#' # see vignette("admtools") for an example
#'

t = get_time(x, obj, ...)

return(t)
}
4 changes: 2 additions & 2 deletions R/time_to_strat.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ time_to_strat = function(obj, x, ...){
#'
#' @description
#' Takes an object and transforms it from the time domain into the stratigraphic domain using the provided age-depth model.
#' Currently implemented for the "phylo" class.
#' Currently implemented for the "phylo", "list", and "numeric" class.
#'
#'
#' @param obj the object to be transformed
Expand All @@ -16,7 +16,7 @@ time_to_strat = function(obj, x, ...){
#'
#' @returns an object of the same type as obj
#'
#' @seealso [strat_to_time()] to transform data from the stratigraphic domain to the time domain, [time_to_strat.phylo()] and [time_to_strat.list()] for details on how to transfrom phylo objects and lists
#' @seealso [strat_to_time()] to transform data from the stratigraphic domain to the time domain, [time_to_strat.phylo()], [time_to_strat.numeric()] and [time_to_strat.list()] for details on how to transfrom phylo objects, vectors, and lists. See [get_height()] for the underlying procedure.
#'

UseMethod("time_to_strat")
Expand Down
2 changes: 1 addition & 1 deletion R/time_to_strat.list.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ time_to_strat.list = function(obj, x, ...){
#' @param x an _adm_ object
#' @param ... options passed to _get_height_
#'
#' @seealso [strat_to_time.list()] for the transformation from height to time domain
#' @seealso [strat_to_time.list()] for the transformation from height to time domain, [time_to_strat.phylo()] and [time_to_strat.numeric()] for transformations of phylogenetic trees and vectors. See [get_height()] for the underlying procedure.
#'
#' @returns a list with one named element "h" instead of the element "t", containing the stratigraphic positions corresponding to the times inf "t"
#'
Expand Down
28 changes: 28 additions & 0 deletions R/time_to_strat.numeric.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
time_to_strat.numeric = function(obj, x, ...){
#'
#' @export
#'
#' @title transform vectors from time to height domain
#'
#' @description
#' This function transforms numeric vectors from the time to the stratigrahpic domain
#' Fundamentally a wrapper around get_height for consistent syntax
#'
#'
#' @param obj a numeric vector, interpreted as timing of events
#' @param x an _adm_ object
#' @param ... options passed to _get_height_
#'
#' @seealso [strat_to_time.numeric()] for the transformation from height to time domain, [time_to_strat.phylo()] and [time_to_strat.list()] for transformations of phylogenetic trees and lists. See [get_height()] for the underlying procedure.
#'
#' @returns a numberic vector - stratigraphic position of the events
#'
#' @examples
#' # see vignette("admtools") for an example
#'


h = get_height(x, t = obj, ...)
return(h)

}
2 changes: 1 addition & 1 deletion R/time_to_strat.phylo.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ time_to_strat.phylo = function(obj, x, ...){
#'
#' @returns a phylo object, representation of the tree in the strat domain
#'
#' @seealso [get_height()] for the underlying procedure, [time_to_strat()] for the higher level function, and [strat_to_time.phylo()] for the transformantion of phylo objects from strat domain to the time domain.
#' @seealso [get_height()] for the underlying procedure, [time_to_strat()] for the higher level function, and [strat_to_time.phylo()] for the transformantion of phylo objects from strat domain to the time domain. See [time_to_strat.list()] and [time_to_strat.numeric()] for the transformation of lists and numeric vectors

tree = obj
adm = x
Expand Down
12 changes: 11 additions & 1 deletion man/plot.multiadm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/strat_to_time.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/strat_to_time.numeric.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/time_to_strat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/time_to_strat.list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/time_to_strat.numeric.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/time_to_strat.phylo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vignettes/adm_from_sedrate.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ For information on estimating age-depth models from tracer contents of rocks and
vignette("adm_from_trace_cont")
```

For details on plotting ADMs see

```{r, eval=FALSE}
vignette("adm_plotting)
```

For an overview of the structure of the `admtools` package and the classes used therein see

```{r, eval=FALSE}
Expand Down
8 changes: 8 additions & 0 deletions vignettes/adm_from_trace_cont.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ For information on estimating age-depth models from sedimentation rates, see
vignette("adm_from_sedrate")
```


For details on plotting ADMs see

```{r, eval=FALSE}
vignette("adm_plotting)
```


For an overview of the structure of the `admtools` package and the classes used therein see

```{r, eval=FALSE}
Expand Down
3 changes: 3 additions & 0 deletions vignettes/adm_plotting.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ plot(adm,
T_axis_lab(label = "Elapsed Model Time")
L_axis_lab(label = "Stratigraphic Height")
```

## Multiple age-depth models (class "multiadm")

By default, `multiadm` plots median ages in red and the 95 % envelope in blue. See also `?plot.multiadm`.


10 changes: 10 additions & 0 deletions vignettes/admtools.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ plot(x = strat_list$h,

Note the jump in traits generated by the erosional interval in `my_adm`.

#### Numeric vectors

Numeric vectors can be transformed using `time_to_strat` and `strat_to_time` too. These are essentially high level wrappers around `get_height` and `get_time`. See functions `time_to_strat.numeric` and `strat_to_time.numeric` for details.

## Further information

For an overview of the structure of the `admtools` package and the classes used therein see
Expand All @@ -310,6 +314,12 @@ For an overview of the structure of the `admtools` package and the classes used
vignette("admtools_doc")
```

For details on plotting ADMs see

```{r, eval=FALSE}
vignette("adm_plotting)
```

For information on estimating age-depth models from sedimentation rates, see

```{r, eval=FALSE}
Expand Down
9 changes: 9 additions & 0 deletions vignettes/admtools_doc.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ The following functions transform `multiadm` objects into other S3 classes:
- `strat_to_time.phylo`: Transform stratigraphic tree into time domain
- `time_to_strat.phylo`: Transform time tree into strat domain

### Class `numeric`

- `strat_to_time.numeric`: Transform vectors from stratigraphic domain to time domain. Wrapper around `get_time`
- `time_to_strat.numeric`: Transform vectors from time to stratigraphic domain. Wrapper around `get_height`

## Plotting

The following functions are used for plotting:
Expand Down Expand Up @@ -264,3 +269,7 @@ The following functions are used internally and not exposed to users. They can b
- `plot_acc_parts`

- `make_adm_canvas`

## Vignettes

- `browseVignettes(package = "admtools")` to show a list of vignettes

0 comments on commit 61bd4e6

Please sign in to comment.