Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

externalized plotting of axis labels #6

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ S3method(strat_to_time,phylo)
S3method(summary,adm)
S3method(summary,multiadm)
S3method(time_to_strat,phylo)
export(L_axis_lab)
export(T_axis_lab)
export(add_adm_to_multiadm)
export(get_completeness)
export(get_height)
Expand Down
54 changes: 54 additions & 0 deletions R/L_axis_lab.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
L_axis_lab = function(label = "Height", unit = TRUE, sep = " ", brac = c("[", "]"), line = 2, outer = FALSE, at = NA,
adj = NA, padj = NA, cex = NA, col = NA, font = NA, ...){

#'
#' @export
#'
#' @title plot height axis label
#'
#' @param label Axis label
#' @param unit Logical or character, should unit be plotted
#' @param sep separater between label and unit
#' @param brac brackets surrounding unit
#' @param line parameter passed to _mtext_, see ?mtext for details
#' @param outer parameter passed to _mtext_, see ?mtext for details
#' @param at parameter passed to _mtext_, see ?mtext for details
#' @param adj parameter passed to _mtext_, see ?mtext for details
#' @param padj parameter passed to _mtext_, see ?mtext for details
#' @param cex parameter passed to _mtext_, see ?mtext for details
#' @param col parameter passed to _mtext_, see ?mtext for details
#' @param font parameter passed to _mtext_, see ?mtext for details
#' @param ... further graphical parameters passed to _mtext_, see ?mtext for details
#'
#' @returns invisible NULL

list = get("adm_plot_info", envir = .adm_plot_env)

L_unit = list$L_unit

if (unit == FALSE){
L_lab = NULL
} else if (unit == TRUE){
if (!is.null(L_unit)){
L_lab = paste0(sep, brac[1], L_unit, brac[2])
} else {
L_lab = NULL
}
} else {
L_lab = paste0(sep, brac[1], unit, brac[2])
}

graphics::mtext(text = paste(label, L_lab, sep = " "),
side = 2,
line = line,
outer = outer,
at = at,
adj = adj,
padj = padj,
cex = cex,
col = col,
font = font,
...)

return(invisible())
}
54 changes: 54 additions & 0 deletions R/T_axis_lab.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
T_axis_lab = function(label = "Time", unit = TRUE, sep = " ", brac = c("[", "]"), line = 2, outer = FALSE, at = NA,
adj = NA, padj = NA, cex = NA, col = NA, font = NA, ...){

#'
#' @export
#'
#' @title plot time axis label
#'
#' @param label Axis label
#' @param unit Logical or character, should unit be plotted
#' @param sep separater between label and unit
#' @param brac brackets surrounding unit
#' @param line parameter passed to _mtext_, see ?mtext for details
#' @param outer parameter passed to _mtext_, see ?mtext for details
#' @param at parameter passed to _mtext_, see ?mtext for details
#' @param adj parameter passed to _mtext_, see ?mtext for details
#' @param padj parameter passed to _mtext_, see ?mtext for details
#' @param cex parameter passed to _mtext_, see ?mtext for details
#' @param col parameter passed to _mtext_, see ?mtext for details
#' @param font parameter passed to _mtext_, see ?mtext for details
#' @param ... further graphical parameters passed to _mtext_, see ?mtext for details
#'
#' @returns invisible NULL

list = get("adm_plot_info", envir = .adm_plot_env)

T_unit = list$T_unit

if (unit == FALSE){
T_lab = NULL
} else if (unit == TRUE){
if (!is.null(T_unit)){
T_lab = paste0(sep, brac[1], T_unit, brac[2])
} else {
T_lab = NULL
}
} else {
T_lab = paste0(sep, brac[1], unit, brac[2])
}

graphics::mtext(text = paste(label, T_lab, sep = " "),
side = 1,
line = line,
outer = outer,
at = at,
adj = adj,
padj = padj,
cex = cex,
col = col,
font = font,
...)

return(invisible())
}
27 changes: 5 additions & 22 deletions R/plot.adm.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,19 @@ plot.adm = function(x, lwd_hiat = 1, lwd_cons = 1, lty_hiat = 3, lty_cons = 1,
#' @param ... arguments passed to plot
#'

assign("adm_plot_info",list("T_unit" = x$T_unit,
"L_unit" = x$L_unit), envir = .adm_plot_env)

adm = x

in_list = list(...)

if ("xlab" %in% names(in_list)){
xlab = in_list[["xlab"]]
} else {
if (is.null(adm$T_unit)) {
xlab = "Time"
} else {
xlab = paste0("Time [", adm$T_unit, "]")
}
}

if ("ylab" %in% names(in_list)){
ylab = in_list[["ylab"]]
} else {
if (is.null(adm$L_unit)) {
ylab = "Height"
} else {
ylab = paste0("Height [", adm$L_unit, "]")
}
}

plot(x = adm$t,
y = adm$h,
type = "l",
lty = "blank",
xlab = xlab,
ylab = ylab,
xlab = "",
ylab = "",
...)


Expand Down
10 changes: 6 additions & 4 deletions R/plot.multiadm.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ plot.multiadm = function(x,...){
mode == "lines"
}

assign("adm_plot_info",list("T_unit" = x$T_unit,
"L_unit" = x$L_unit), envir = .adm_plot_env)

multiadm = x

Expand All @@ -36,8 +38,8 @@ plot.multiadm = function(x,...){
plot(NULL,
xlim = c(t_min, t_max),
ylim = c(h_min, h_max),
xlab = "Time",
ylab = "Height")
xlab = "",
ylab = "")

for ( i in seq_len(no_of_entries)){
graphics::lines(multiadm$t[[i]], multiadm$h[[i]])
Expand All @@ -54,8 +56,8 @@ plot.multiadm = function(x,...){
plot(NULL,
xlim = c(t_min, t_max),
ylim = c(h_min, h_max),
xlab = "Time",
ylab = "Height")
xlab = "",
ylab = "")

h = seq(h_min, h_max, length.out = 100)
h_list = get_time(multiadm, h)
Expand Down
9 changes: 6 additions & 3 deletions R/sedrate_to_multiadm.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100){
sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100L,
T_unit = NULL, L_unit = NULL){

#'
#' @title Estimate age-depth model from sedimentation rate & tie points
Expand All @@ -8,6 +9,8 @@ sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100){
#' @param sed_rate_gen : function, returns sedimentation rate functions
#' @param h : numeric, heights where the adm is calculated
#' @param no_of_rep : numeric, number of repetitions
#' @param T_unit time unit
#' @param L_unit length unit
#'
#' @returns object of class multiadm
#'
Expand Down Expand Up @@ -56,8 +59,8 @@ sedrate_to_multiadm = function(h_tp, t_tp, sed_rate_gen, h, no_of_rep = 100){
multiadm = list(t = t_list,
h = h_list,
destr = destr_list,
T_unit = NA,
L_unit = NA,
T_unit = T_unit,
L_unit = L_unit,
no_of_entries = length(t_list))
class(multiadm) = "multiadm"
return(multiadm)
Expand Down
9 changes: 6 additions & 3 deletions R/strat_cont_to_multiadm.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
strat_cont_to_multiadm = function(h_tp, t_tp, strat_cont_gen, time_cont_gen, h, no_of_rep = 100L, subdivisions = 100L){
strat_cont_to_multiadm = function(h_tp, t_tp, strat_cont_gen, time_cont_gen, h, no_of_rep = 100L, subdivisions = 100L,
T_unit = NULL, L_unit = NULL){

#'
#' @title estimate age-depth model from stratigraphic contents
Expand All @@ -10,6 +11,8 @@ strat_cont_to_multiadm = function(h_tp, t_tp, strat_cont_gen, time_cont_gen, h,
#' @param h heights where the adm is evaluated
#' @param no_of_rep integer, number of repetititons
#' @param subdivisions integer, max no. of subintervals used by integration procedure
#' @param T_unit time unit
#' @param L_unit length unit
#'
#' @returns Object of class multiadm
#'
Expand Down Expand Up @@ -91,8 +94,8 @@ strat_cont_to_multiadm = function(h_tp, t_tp, strat_cont_gen, time_cont_gen, h,
multiadm = list(t = t_list,
h = h_list,
destr = destr_list,
T_unit = NA,
L_unit = NA,
T_unit = T_unit,
L_unit = L_unit,
no_of_entries = length(t_list))
class(multiadm) = "multiadm"
return(multiadm)
Expand Down
3 changes: 3 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


.adm_plot_env <- new.env()
55 changes: 55 additions & 0 deletions man/L_axis_lab.Rd

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

55 changes: 55 additions & 0 deletions man/T_axis_lab.Rd

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

14 changes: 13 additions & 1 deletion man/sedrate_to_multiadm.Rd

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

Loading