diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index 7d6924ce..a205bdd1 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -44,6 +44,7 @@ #' @param dot_size plot dot size. #' @param plot_relative_height_value numeric value between 500 and 5000 for controlling the starting value #' of the relative plot height slider +#' @param xlab an x-axis label, if \code{NULL} then the behavior as in `xlab` from \link[goshawk]{g_lineplot} #' @author Wenyi Liu (luiw2) wenyi.liu@roche.com #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' @@ -147,6 +148,7 @@ tm_g_gh_lineplot <- function(label, )[1:4], xtick = ggplot2::waiver(), xlabel = xtick, + xlab = "Analysis Visit", rotate_xlab = FALSE, plot_height = c(600, 200, 4000), plot_width = NULL, @@ -201,6 +203,9 @@ tm_g_gh_lineplot <- function(label, # Validate line arguments validate_line_arb_arg(hline_arb, hline_arb_color, hline_arb_label) + # Validate character labels + checkmate::assert_string(xlab, null.ok = TRUE) + args <- as.list(environment()) module( @@ -277,7 +282,8 @@ ui_lineplot <- function(id, ...) { value = c(-1000000, 1000000) ), checkboxInput(ns("rotate_xlab"), "Rotate X-axis Label", a$rotate_xlab), - numericInput(ns("count_threshold"), "Contributing Observations Threshold:", a$count_threshold) + numericInput(ns("count_threshold"), "Contributing Observations Threshold:", a$count_threshold), + textInput(ns("xlab"), "X-axis Label", a$xlab) ), teal.widgets::panel_item( title = "Plot settings", @@ -720,6 +726,7 @@ srv_lineplot <- function(id, " ) } + xlab <- if (is.null(input$xlab)) xaxis else input$xlab hline_arb <- horizontal_line()$line_arb hline_arb_label <- horizontal_line()$line_arb_label @@ -749,6 +756,7 @@ srv_lineplot <- function(id, hline_arb_color = .(hline_arb_color), xtick = .(if (!is.null(xtick)) quote(xtick) else xtick), xlabel = .(if (!is.null(xtick)) quote(xlabel) else xlabel), + xlab = .(xlab), rotate_xlab = .(rotate_xlab), plot_height = .(relative_height), # in g_lineplot this is relative height of plot to table plot_font_size = .(plot_font_size), diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index 3a3ce894..da762e08 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -46,6 +46,7 @@ #' @param hline_vars_colors a character vector naming the colors for the additional horizontal lines. #' @param hline_vars_labels a character vector naming the labels for the additional horizontal lines that will appear #' in the legend. +#' @param xlab an `x-axis` label, if \code{NULL} then no label is displayed #' @inheritParams teal.widgets::standard_layout #' #' @author Wenyi Liu (luiw2) wenyi.liu@roche.com @@ -176,6 +177,7 @@ tm_g_gh_spaghettiplot <- function(label, color_comb = NULL, xtick = ggplot2::waiver(), xlabel = xtick, + xlab = "Analysis Visit", rotate_xlab = FALSE, facet_ncol = 2, free_x = FALSE, @@ -236,6 +238,9 @@ tm_g_gh_spaghettiplot <- function(label, validate_line_arb_arg(hline_arb, hline_arb_color, hline_arb_label) validate_line_vars_arg(hline_vars, hline_vars_colors, hline_vars_labels) + # Validate character labels + checkmate::assert_string(xlab, null.ok = TRUE) + args <- as.list(environment()) module( @@ -320,6 +325,7 @@ g_ui_spaghettiplot <- function(id, ...) { ), checkboxInput(ns("free_x"), "Free X-Axis Scales", a$free_x), checkboxInput(ns("rotate_xlab"), "Rotate X-Axis Label", a$rotate_xlab), + textInput(ns("xlab"), "X-axis Label", a$xlab), teal.widgets::optionalSliderInputValMinMax(ns("font_size"), "Font Size", a$font_size, ticks = FALSE), teal.widgets::optionalSliderInputValMinMax(ns("dot_size"), "Dot Size", a$dot_size, ticks = FALSE), teal.widgets::optionalSliderInputValMinMax( @@ -474,6 +480,8 @@ srv_g_spaghettiplot <- function(id, ) } + xlab <- input$xlab + teal.code::eval_code( object = private_qenv, code = bquote({ @@ -498,6 +506,7 @@ srv_g_spaghettiplot <- function(id, hline_arb_color = .(hline_arb_color), xtick = xtick, xlabel = xlabel, + xlab = .(xlab), rotate_xlab = .(rotate_xlab), font_size = .(font_size), dot_size = .(dot_size), diff --git a/man/tm_g_gh_lineplot.Rd b/man/tm_g_gh_lineplot.Rd index c307d9b6..1d7e5933 100644 --- a/man/tm_g_gh_lineplot.Rd +++ b/man/tm_g_gh_lineplot.Rd @@ -26,6 +26,7 @@ tm_g_gh_lineplot( "#4ca3dd", "#8a2be2"))[1:4], xtick = ggplot2::waiver(), xlabel = xtick, + xlab = "Analysis Visit", rotate_xlab = FALSE, plot_height = c(600, 200, 4000), plot_width = NULL, @@ -90,6 +91,8 @@ Default value is waive().} \item{xlabel}{vector with same length of \code{xtick} to define the label of x-axis tick values. Default value is waive().} +\item{xlab}{an x-axis label, if \code{NULL} then the behavior as in \code{xlab} from \link[goshawk]{g_lineplot}} + \item{rotate_xlab}{\code{logical(1)} value indicating whether to rotate \code{x-axis} labels.} \item{plot_height}{controls plot height.} diff --git a/man/tm_g_gh_spaghettiplot.Rd b/man/tm_g_gh_spaghettiplot.Rd index 27a4bdf0..e79f3221 100644 --- a/man/tm_g_gh_spaghettiplot.Rd +++ b/man/tm_g_gh_spaghettiplot.Rd @@ -22,6 +22,7 @@ tm_g_gh_spaghettiplot( color_comb = NULL, xtick = ggplot2::waiver(), xlabel = xtick, + xlab = "Analysis Visit", rotate_xlab = FALSE, facet_ncol = 2, free_x = FALSE, @@ -83,6 +84,8 @@ when x variable is numeric. Default value is \code{waive()}.} \item{xlabel}{vector with same length of \code{xtick} to define the label of \code{x-axis} tick values. Default value is \code{waive()}.} +\item{xlab}{an \code{x-axis} label, if \code{NULL} then no label is displayed} + \item{rotate_xlab}{\code{logical(1)} value indicating whether to rotate \code{x-axis} labels} \item{facet_ncol}{numeric value indicating number of facets per row.}