### Setup R Environment for Data Checking Source: https://opensource.nibr.com/xgx/Data_Checking This R code block initializes the environment by loading essential libraries such as 'tidyverse' for data manipulation, 'DT' for interactive tables, and 'xgxr' for specialized graphics. It also configures global options for 'knitr' chunks, setting default figure dimensions, and adjusts 'DT' table options for display, alongside defining common covariates and time units. ```R library(tidyverse) library(DT) library(xgxr) #set chunk default options xgx_theme_set() knitr::opts_chunk_set(warning = FALSE, message = FALSE, fig.height = 4, fig.width = 4) options(DT.options = list(pageLength = 20)) #pageLength = number of entries per page #specify the time units and your covariates covariates = c("WEIGHT0","AGE0","SEX","WEIGHT0_CAT") time_units_dataset = "days" ``` -------------------------------- ### R Example: Plotting Data with xgx_geom_pi Source: https://opensource.nibr.com/xgx/r/reference/xgx_geom_pi An example demonstrating how to use `xgx_geom_pi` with sample data and `ggplot2` to visualize median and percent intervals, showing basic setup and function call. ```R data <- data.frame(x = rep(c(1, 2, 3), each = 20), y = rep(c(1, 2, 3), each = 20) + stats::rnorm(60)) ggplot2::ggplot(data, ggplot2::aes(x = x, y = y)) + xgx_geom_pi(percent_level = 0.95) ``` -------------------------------- ### Example Usage of xgx_auto_explore for PK Data Source: https://opensource.nibr.com/xgx/r/reference/xgx_auto_explore This R example demonstrates how to use `xgx_auto_explore` with a `nonlinear_pkpd` dataset to generate a Multiple Ascending Dose PK Rmd template report. It shows how to define column mappings, specify PK/PD compartments, dosing parameters, and output paths. ```R author_name = "Your Name Here" show_explanation = FALSE if (FALSE) { # Try out the nonlinear_pkpd dataset with the # Multiple Ascending Dose PK Rmd template data_path <- "~/nonlinear_pkpd.csv" # Specify the mapping of column names mapping <- list( "TIME" = "TIM2", "NOMTIME" = "NT", "EVID" = 0, "CENS" = 0, "DOSE" = "MGKG", "TRTACT" = "TRT", "LIDV_NORM" = "LIDV/MGKG", "LIDV_UNIT" = "UNIT", "PROFDAY" = 1, "SEX" = 0, "WEIGHTB" = 0) # 5 contains the PK Concentration in this dataset pk_cmt = 5 # We don't need PD right now pd_cmt = NULL pd_data_type = NULL dose_cmt = 1 steady_state_day = c(0, 6) time_between_doses = 24 multiple_dosing = TRUE output_directory = tempdir() xgx_auto_explore(data_path = data_path, mapping = mapping, author_name = author_name, pk_cmt = pk_cmt, pd_cmt = pd_cmt, dose_cmt = dose_cmt, steady_state_day = steady_state_day, time_between_doses = time_between_doses, multiple_dosing = multiple_dosing, pd_data_type = pd_data_type, rmd_output_path = output_directory, show_explanation = show_explanation) } ``` -------------------------------- ### Setup R Environment and Load Libraries Source: https://opensource.nibr.com/xgx/Rmarkdown/Oncology_Efficacy_Plots Initializes the R environment by loading necessary packages for data manipulation, plotting, and statistical analysis. It also sets up global ggplot2 themes for consistent visualization and defines a status flag for figures. ```R library(ggplot2) library(dplyr) library(tidyr) library(gridExtra) library(zoo) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() ``` -------------------------------- ### R Environment Setup for xGx Data Analysis Source: https://opensource.nibr.com/xgx/Datasets This R code block initializes essential libraries for data manipulation (dplyr, tidyr), visualization (ggplot2), and specific xGx functionalities (xgxr). It also applies the default xGx theme for consistent plotting across the project. ```R library(ggplot2) library(dplyr) library(tidyr) library(xgxr) xgx_theme_set() ``` -------------------------------- ### Initialize R Environment and Setup Directories Source: https://opensource.nibr.com/xgx/Multiple_Ascending_Dose_PKPD_count This R code snippet initializes necessary libraries for data manipulation and plotting, sets a draft status flag, configures ggplot themes, and defines a list of directory paths and filenames for saving generated plots and scripts. ```R library(ggplot2) library(dplyr) library(tidyr) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = "Parent_Directory", rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### R Example: Plotting Mean and Confidence Intervals with xgx_stat_ci Source: https://opensource.nibr.com/xgx/r/reference/xgx_stat_ci This example demonstrates how to use `xgx_stat_ci` to plot mean and 95% confidence intervals for normally distributed data. It shows data generation, plot initialization with `xgx_plot`, and adding the `xgx_stat_ci` layer to visualize the data. ```R # default settings for normally distributed data, 95% confidence interval, data <- data.frame(x = rep(c(1, 2, 3), each = 20), y = rep(c(1, 2, 3), each = 20) + stats::rnorm(60), group = rep(1:3, 20)) xgx_plot(data, ggplot2::aes(x = x, y = y)) + xgx_stat_ci(conf_level = 0.95) ``` -------------------------------- ### Example Usage of xgx_plot for Data Visualization Source: https://opensource.nibr.com/xgx/r/reference/xgx_plot Demonstrates how to use `xgx_plot` with sample data to create a line and point plot. It shows data preparation and integration with `ggplot2::geom_line()` and `ggplot2::geom_point()` to visualize time-concentration data for multiple IDs. ```R time <- rep(seq(1, 10), 5) id <- sort(rep(seq(1, 5), 10)) conc <- exp(-time) * sort(rep(stats::rlnorm(5), 10)) data <- data.frame(time = time, concentration = conc, id = id) xgx_plot(data = data, mapping = ggplot2::aes(x = time, y = concentration, group = id)) + ggplot2::geom_line() + ggplot2::geom_point() ``` -------------------------------- ### Apply xGx Theme to ggplot2 Plot Example Source: https://opensource.nibr.com/xgx/r/reference/theme_xgx Demonstrates how to use `theme_xgx()` within a ggplot2 pipeline. This example generates sample concentration-response data, plots it using `ggplot2::geom_point()` and `ggplot2::geom_line()`, applies xgx-specific log scales (`xgx_scale_y_log10`, `xgx_scale_x_reverselog10`), and finally applies the `theme_xgx()` to style the plot. ```R conc <- 10^(seq(-3, 3, by = 0.1)) ec50 <- 1 data <- data.frame(concentration = conc, bound_receptor = 1 * conc / (conc + ec50)) ggplot2::ggplot(data, ggplot2::aes(y = concentration, x = bound_receptor)) + ggplot2::geom_point() + ggplot2::geom_line() + xgx_scale_y_log10() + xgx_scale_x_reverselog10() + theme_xgx() ``` -------------------------------- ### Setup R Environment and Configure Plotting Source: https://opensource.nibr.com/xgx/Multiple_Ascending_Dose_PD_ordinal This R code block initializes the environment by loading essential libraries for data manipulation (dplyr, tidyr), plotting (ggplot2, gridExtra), and specific `xgxr` utilities. It also sets a draft status flag, applies a custom `xgx` ggplot theme, and defines directory paths for saving generated figures, ensuring a consistent setup for subsequent analysis and plotting. ```R library(ggplot2) library(dplyr) library(tidyr) library(gridExtra) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = tempdir(), rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### R Environment Setup and Library Loading Source: https://opensource.nibr.com/xgx/Rmarkdown/Adverse_Events Initializes the R environment by loading essential libraries such as `ggplot2`, `dplyr`, `tidyr`, `gridExtra`, `zoo`, and `xgxr`. It also sets a global status flag and applies `xgxr`'s default `ggplot2` theme settings for consistent plotting. ```R library(ggplot2) library(dplyr) library(tidyr) library(gridExtra) library(zoo) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() ``` -------------------------------- ### Display R Session Information Source: https://opensource.nibr.com/xgx/Data_Checking This R code snippet prints detailed information about the current R session, including the R version, platform, running environment, and loaded packages. This is crucial for reproducibility and debugging, ensuring that the analysis environment can be replicated. ```R sessionInfo() ``` -------------------------------- ### R Environment Setup and Global Options Source: https://opensource.nibr.com/xgx/Rmarkdown/Data_Checking Loads necessary R libraries (tidyverse, DT, xgxr) and sets global chunk options for knitr, including figure dimensions and DT table pagination. Also defines covariates and time units for subsequent analysis. ```R library(tidyverse) library(DT) library(xgxr) #set chunk default options xgx_theme_set() knitr::opts_chunk$set(warning = FALSE, message = FALSE, fig.height = 4, fig.width = 4) options(DT.options = list(pageLength = 20)) #specify the time units and your covariates covariates = c("WEIGHT0","AGE0","SEX","WEIGHT0_CAT") time_units_dataset = "days" ``` -------------------------------- ### Examples of xgx_breaks_log10 Usage in R Source: https://opensource.nibr.com/xgx/r/reference/xgx_breaks_log10 Illustrative R code examples demonstrating the application of the `xgx_breaks_log10` function with various input data ranges. These examples showcase how the function generates appropriate log10 breaks for different scales, from wide ranges to very narrow ones, and how it handles edge cases. ```R xgx_breaks_log10(c(1, 1000)) #> [1] 1 10 100 1000 xgx_breaks_log10(c(0.001, 100)) #> [1] 1e-03 1e-02 1e-01 1e+00 1e+01 1e+02 xgx_breaks_log10(c(1e-4, 1e4)) #> [1] 1e-04 1e-02 1e+00 1e+02 1e+04 xgx_breaks_log10(c(1e-9, 1e9)) #> [1] 1e-10 1e-05 1e+00 1e+05 1e+10 xgx_breaks_log10(c(1, 2)) #> [1] 1 2 xgx_breaks_log10(c(1, 5)) #> [1] 1 2 3 4 5 xgx_breaks_log10(c(1, 10)) #> [1] 1 2 3 4 6 10 xgx_breaks_log10(c(1, 100)) #> [1] 1 3 10 30 100 xgx_breaks_log10(c(1, 1.01)) #> [1] 1.00 1.01 xgx_breaks_log10(c(1, 1.0001)) #> [1] 1.000000 1.000023 1.000046 1.000069 1.000092 print(xgx_breaks_log10(c(1, 1.000001)), digits = 10) #> [1] 1.000000000 1.000000230 1.000000461 1.000000691 1.000000921 ``` -------------------------------- ### R ggplot2 Example: Applying xgx_scale_y_log10 to a Plot Source: https://opensource.nibr.com/xgx/r/reference/xgx_scale_y_log10 This R code provides a practical example of how to integrate `xgx_scale_y_log10` into a ggplot2 visualization. It constructs a data frame representing concentration-response, then generates a scatter plot with a line. The example demonstrates applying `xgx_scale_y_log10` to the y-axis for custom log scaling and `xgx_scale_x_reverselog10` to the x-axis, showcasing the function's usage in a typical data plotting scenario. ```R conc <- 10^(seq(-3, 3, by = 0.1)) ec50 <- 1 data <- data.frame(concentration = conc, bound_receptor = 1 * conc / (conc + ec50)) ggplot2::ggplot(data, ggplot2::aes(y = concentration, x = bound_receptor)) + ggplot2::geom_point() + ggplot2::geom_line() + xgx_scale_y_log10() + xgx_scale_x_reverselog10() ``` -------------------------------- ### R Examples for xgx_breaks_time function Source: https://opensource.nibr.com/xgx/r/reference/xgx_breaks_time Illustrative examples demonstrating the usage of the `xgx_breaks_time` function with various data ranges and time units (hour, day, week) to generate appropriate axis breaks. ```R xgx_breaks_time(c(0, 5), "hour") #> [1] 0.0 0.6 1.2 1.8 2.4 3.0 3.6 4.2 4.8 xgx_breaks_time(c(0, 6), "hour") #> [1] 0.0 0.6 1.2 1.8 2.4 3.0 3.6 4.2 4.8 5.4 6.0 xgx_breaks_time(c(-3, 5), "hour") #> [1] -3 0 3 6 xgx_breaks_time(c(0, 24), "hour") #> [1] 0 3 6 9 12 15 18 21 24 xgx_breaks_time(c(0, 12), "hour") #> [1] 0 3 6 9 12 xgx_breaks_time(c(1, 4), "day") #> [1] 1 2 3 4 xgx_breaks_time(c(1, 12), "day") #> [1] 0 3 6 9 12 xgx_breaks_time(c(1, 14), "day") #> [1] 0 7 14 xgx_breaks_time(c(1, 50), "day") #> [1] 0 7 14 21 28 35 42 49 xgx_breaks_time(c(1000, 3000), "day") #> [1] 1080 1440 1800 2160 2520 2880 xgx_breaks_time(c(-21, 100), "day") #> [1] -30 0 30 60 90 xgx_breaks_time(c(-1, 10), "week") #> [1] 0 2 4 6 8 10 ``` -------------------------------- ### Initialize R Environment and Load PK Analysis Libraries Source: https://opensource.nibr.com/xgx/Rmarkdown/Multiple_Ascending_Dose_PK_KeyPlots This R script block sets up the necessary environment for pharmacokinetic data analysis and visualization. It loads key R packages such as `ggplot2`, `tidyr`, `dplyr`, `stringr`, and `xgxr`. Additionally, it defines a 'DRAFT' status flag for figures and configures `ggplot`'s default theme using `xgx_theme_set()`. Directory paths for saving generated plots are also initialized. ```R #add key packages library(ggplot2) library(tidyr) library(dplyr) library(stringr) library(xgxr)#, lib.loc = "../Rlib") #flag for labeling figures as draft status = "DRAFT" # ggplot settings xgx_theme_set() # directories for saving individual graphs dirs = list( parent_dir= "Parent_Directory", rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### R Example: Generate Plot Caption with xgx_dirs2char Source: https://opensource.nibr.com/xgx/r/reference/xgx_dirs2char Demonstrates how to use the `xgx_dirs2char` function in R. It shows how to construct the `dirs` list with example path components and then calls the function to generate a `caption` string suitable for plot annotations. ```R dirs <- list(parent_dir = "/your/parent/path/", rscript_dir = "./Rscripts/", rscript_name = "Example.R", results_dir = "./Results/", filename = "your_file_name.png") caption <- xgx_dirs2char(dirs) ``` -------------------------------- ### Setup R Environment for PK/PD Data Analysis and Plotting Source: https://opensource.nibr.com/xgx/Multiple_Ascending_Dose_PD_real_example This R code snippet initializes the analytical environment by loading essential libraries: `ggplot2` for data visualization, `dplyr` for data manipulation, `caTools` for utility functions, and `xgxr` for applying specific graphical themes. It also defines a global status flag for labeling figures as 'DRAFT' and configures `ggplot2` with `xgxr`'s default theme settings, preparing the workspace for subsequent data processing and plotting. ```R # library(rmarkdown) library(ggplot2) library(dplyr) library(caTools) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() ``` -------------------------------- ### R Environment Setup and Configuration Source: https://opensource.nibr.com/xgx/Rmarkdown/Multiple_Ascending_Dose_PD_binary This R code snippet initializes the environment by loading essential libraries for data manipulation (dplyr, tidyr), plotting (ggplot2, xgxr), and grid arrangement (gridExtra). It also sets a random seed for reproducible jitter in plots, defines a 'DRAFT' status flag for figures, configures global ggplot themes using `xgx_theme_set()`, and establishes a directory structure for saving generated plots. ```R library(gridExtra) library(ggplot2) library(dplyr) library(xgxr) library(tidyr) #set seed for random number generator (for plots with jitter) set.seed(12345) #flag for labeling figures as draft status = "DRAFT" # ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = "Parent_Directory", rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### R: Example Usage of xgx_annotate_filenames with ggplot2 Source: https://opensource.nibr.com/xgx/r/reference/xgx_annotate_filenames This example demonstrates how to use the `xgx_annotate_filenames` function to add file details to a `ggplot2` plot. It shows how to prepare the `dirs` list with necessary path information and integrate the function into a plot creation pipeline. ```R dirs <- list(parent_dir = "/your/parent/path/", rscript_dir = "./Rscripts/", rscript_name = "Example.R", results_dir = "./Results/", filename = "your_file_name.png") data <- data.frame(x = 1:1000, y = rnorm(1000)) ggplot2::ggplot(data = data, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point() + xgx_annotate_filenames(dirs) ``` -------------------------------- ### Example Usage of xgx_annotate_status_png in R Source: https://opensource.nibr.com/xgx/r/reference/xgx_annotate_status_png This R code example demonstrates how to use `xgx_annotate_status_png` to annotate a single PNG file. It first creates a temporary PNG file with a plot, then calls the annotation function to add a status and script name. ```R # using the examples from plot() file.name <- tempfile() grDevices::png(file.name) graphics::plot(cars) graphics::lines(stats::lowess(cars)) grDevices::dev.off() #> agg_png #> 2 # annotate one file xgx_annotate_status_png(file.name, "/tmp/script1.R") ``` -------------------------------- ### R Environment Setup for PK Data Analysis Source: https://opensource.nibr.com/xgx/Rmarkdown/Single_Ascending_Dose_PK This snippet loads necessary R packages like `ggplot2`, `dplyr`, `tidyr`, and `xgxr` for data manipulation and visualization. It also defines global settings for `ggplot2` themes and directory paths for saving figures, ensuring consistent output and easy file management. ```R library(ggplot2) library(dplyr) library(tidyr) library(xgxr) #flag for labeling figures as draft status = "DRAFT" # ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = "Parent_Directory", rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### Load and Preprocess Data for Checking Source: https://opensource.nibr.com/xgx/Data_Checking This R code snippet demonstrates how to load a CSV dataset and perform initial preprocessing. It standardizes column names to a consistent format required for data checking (e.g., USUBJID, TIME, AMT, LIDV), ensuring data integrity and compatibility with subsequent analysis steps. The data is then arranged by treatment arm, and a separate dataset is created containing unique subject identifiers. ```R filename = "../Data/Data_Checking.csv" data_in = read.csv(filename, stringsAsFactors = FALSE) data = data_in %>% # in this mutate command are all columns that are required for this check # if your dataset has different naming convention, # then rename the right hand side of the equality mutate(USUBJID = USUBJID, # Unique subject identifier TIME = TIME, # Actual Time NOMTIME = NOMTIME, # Nominal Time AMT = AMT, # Dose Amount LIDV = LIDV, # Dependent variable YTYPE = YTYPE, # Number for type of dependent variable NAME = NAME, # Name for the type of dependent variable (e.g. PK) MDV = MDV, # Missing Dependent Varibale (0 = no, 1 = yes) CENS = CENS, # Censored Data (0 = no, 1 = yes) EVID = EVID, # Event ID. 0 = Dependent Variabale, 1 = dose TRT = TRT, # Treatment Arm character description TRTN = TRTN) %>%# Treatment Arm numeric description (used for sorting) arrange(TRTN) %>% mutate(TRT_low2high = factor(TRT, levels = unique(TRT)), TRT_high2low = factor(TRT, levels = rev(unique(TRT)))) data1 = data %>% filter(!duplicated(USUBJID)) ``` -------------------------------- ### Setup R Environment for Ordinal Data Analysis Source: https://opensource.nibr.com/xgx/Rmarkdown/Multiple_Ascending_Dose_PKPD_ordinal This snippet initializes the R environment by loading necessary libraries such as `ggplot2`, `dplyr`, `tidyr`, `gridExtra`, and `xgxr`. It also sets up global plotting themes and defines directory paths for saving outputs, preparing the workspace for data analysis and visualization. ```R library(ggplot2) library(dplyr) library(tidyr) library(gridExtra) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = tempdir(), rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### R Examples: Generate Minor Breaks for Log10 Scales Source: https://opensource.nibr.com/xgx/r/reference/xgx_minor_breaks_log10 Demonstrates the usage of the `xgx_minor_breaks_log10` function with various input data ranges. These examples illustrate how the function calculates and returns appropriate minor breaks for different logarithmic scales, including cases with very small, very large, and narrow ranges. ```R xgx_minor_breaks_log10(c(1, 1000)) #> [1] 2 3 4 5 6 7 8 9 20 30 40 50 60 70 80 90 200 300 400 #> [20] 500 600 700 800 900 xgx_minor_breaks_log10(c(0.001, 100)) #> [1] 2e-03 3e-03 4e-03 5e-03 6e-03 7e-03 8e-03 9e-03 2e-02 3e-02 4e-02 5e-02 #> [13] 6e-02 7e-02 8e-02 9e-02 2e-01 3e-01 4e-01 5e-01 6e-01 7e-01 8e-01 9e-01 #> [25] 2e+00 3e+00 4e+00 5e+00 6e+00 7e+00 8e+00 9e+00 2e+01 3e+01 4e+01 5e+01 #> [37] 6e+01 7e+01 8e+01 9e+01 xgx_minor_breaks_log10(c(1e-4, 1e4)) #> [1] 2e-04 3e-04 4e-04 5e-04 6e-04 7e-04 8e-04 9e-04 2e-03 3e-03 4e-03 5e-03 #> [13] 6e-03 7e-03 8e-03 9e-03 2e-02 3e-02 4e-02 5e-02 6e-02 7e-02 8e-02 9e-02 #> [25] 2e-01 3e-01 4e-01 5e-01 6e-01 7e-01 8e-01 9e-01 2e+00 3e+00 4e+00 5e+00 #> [37] 6e+00 7e+00 8e+00 9e+00 2e+01 3e+01 4e+01 5e+01 6e+01 7e+01 8e+01 9e+01 #> [49] 2e+02 3e+02 4e+02 5e+02 6e+02 7e+02 8e+02 9e+02 2e+03 3e+03 4e+03 5e+03 #> [61] 6e+03 7e+03 8e+03 9e+03 xgx_minor_breaks_log10(c(1e-9, 1e9)) #> [1] 2e-09 3e-09 4e-09 5e-09 6e-09 7e-09 8e-09 9e-09 2e-08 3e-08 4e-08 5e-08 #> [13] 6e-08 7e-08 8e-08 9e-08 2e-07 3e-07 4e-07 5e-07 6e-07 7e-07 8e-07 9e-07 #> [25] 2e-06 3e-06 4e-06 5e-06 6e-06 7e-06 8e-06 9e-06 2e-05 3e-05 4e-05 5e-05 #> [37] 6e-05 7e-05 8e-05 9e-05 2e-04 3e-04 4e-04 5e-04 6e-04 7e-04 8e-04 9e-04 #> [49] 2e-03 3e-03 4e-03 5e-03 6e-03 7e-03 8e-03 9e-03 2e-02 3e-02 4e-02 5e-02 #> [61] 6e-02 7e-02 8e-02 9e-02 2e-01 3e-01 4e-01 5e-01 6e-01 7e-01 8e-01 9e-01 #> [73] 2e+00 3e+00 4e+00 5e+00 6e+00 7e+00 8e+00 9e+00 2e+01 3e+01 4e+01 5e+01 #> [85] 6e+01 7e+01 8e+01 9e+01 2e+02 3e+02 4e+02 5e+02 6e+02 7e+02 8e+02 9e+02 #> [97] 2e+03 3e+03 4e+03 5e+03 6e+03 7e+03 8e+03 9e+03 2e+04 3e+04 4e+04 5e+04 #> [109] 6e+04 7e+04 8e+04 9e+04 2e+05 3e+05 4e+05 5e+05 6e+05 7e+05 8e+05 9e+05 #> [121] 2e+06 3e+06 4e+06 5e+06 6e+06 7e+06 8e+06 9e+06 2e+07 3e+07 4e+07 5e+07 #> [133] 6e+07 7e+07 8e+07 9e+07 2e+08 3e+08 4e+08 5e+08 6e+08 7e+08 8e+08 9e+08 xgx_minor_breaks_log10(c(1, 2)) #> [1] 2 xgx_minor_breaks_log10(c(1, 5)) #> [1] 2 3 4 5 xgx_minor_breaks_log10(c(1, 10)) #> [1] 2 3 4 5 6 7 8 9 xgx_minor_breaks_log10(c(1, 100)) #> [1] 2 3 4 5 6 7 8 9 20 30 40 50 60 70 80 90 xgx_minor_breaks_log10(c(1, 1.01)) #> numeric(0) xgx_minor_breaks_log10(c(1, 1.0001)) #> numeric(0) print(xgx_minor_breaks_log10(c(1, 1.000001)), digits = 10) #> numeric(0) ``` -------------------------------- ### Example R Usage: Saving a Data Frame as an Image with xgx_save_table Source: https://opensource.nibr.com/xgx/r/reference/xgx_save_table This R code snippet demonstrates how to use the `xgx_save_table` function. It sets up a temporary directory, defines directory parameters, creates a sample data frame, and then calls `xgx_save_table` to save the data, illustrating the function's practical application. ```R directory = tempdir() dirs <- list(parent_dir = directory, rscript_dir = directory, rscript_name = "example.R", results_dir = directory, filename_prefix = "example_") data <- data.frame(x = c(1, 2), y = c(1, 2)) xgx_save_table(data, dirs = dirs, filename_main = "test") ``` -------------------------------- ### Example Usage of xgx_scale_x_log10 in ggplot2 Source: https://opensource.nibr.com/xgx/r/reference/xgx_scale_x_log10 This R example demonstrates how to use `xgx_scale_x_log10` to apply a custom log10 scale to the x-axis of a ggplot2 plot. It creates sample concentration-response data, plots it with points and lines, and applies both `xgx_scale_x_log10` and `xgx_scale_y_reverselog10` to visualize the data effectively. ```R conc <- 10^(seq(-3, 3, by = 0.1)) ec50 <- 1 data <- data.frame(concentration = conc, bound_receptor = 1 * conc / (conc + ec50)) ggplot2::ggplot(data, ggplot2::aes(x = concentration, y = bound_receptor)) + ggplot2::geom_point() + ggplot2::geom_line() + xgx_scale_x_log10() + xgx_scale_y_reverselog10() ``` -------------------------------- ### R Example: Save ggplot to Temporary Directory with xgx_save Source: https://opensource.nibr.com/xgx/r/reference/xgx_save This R code example demonstrates how to use the `xgx_save` function to save a ggplot object. It sets up a temporary directory, defines custom directory paths, creates a sample scatter plot, and then saves it using `xgx_save` with specified dimensions, a main filename, and a 'DRAFT' status. ```R directory = tempdir() dirs <- list(parent_dir = directory, rscript_dir = directory, rscript_name = "example.R", results_dir = directory, filename_prefix = "example_") data <- data.frame(x = 1:1000, y = stats::rnorm(1000)) ggplot2::ggplot(data = data, ggplot2::aes(x = x, y = y)) + ggplot2::geom_point() xgx_save(4, 4, dirs, "Example", "DRAFT") ``` -------------------------------- ### Setup R Environment for PD Exploratory Analysis Source: https://opensource.nibr.com/xgx/Rmarkdown/Multiple_Ascending_Dose_PD_real_example This snippet loads essential R libraries required for data manipulation and visualization, including `ggplot2` for plotting, `dplyr` for data wrangling, `caTools` for utility functions, and `xgxr` for specialized graphical extensions. It also sets up global `ggplot` themes for consistent plot aesthetics and initializes a 'status' flag for labeling figures as 'DRAFT'. ```R library(ggplot2) library(dplyr) library(caTools) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() ``` -------------------------------- ### Setup R Environment for PK/PD Continuous Data Analysis Source: https://opensource.nibr.com/xgx/Multiple_Ascending_Dose_PKPD_continuous This R code snippet initializes the environment by loading essential libraries such as `ggplot2`, `dplyr`, `tidyr`, `gridExtra`, and `xgxr`. It configures `ggplot2` settings using `xgx_theme_set()` and defines a status flag for figures, along with a list of directory paths for managing output files. ```R library(ggplot2) library(dplyr) library(tidyr) library(gridExtra) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir= tempdir(), rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### R Example: Calculate Confidence Interval with xgx_conf_int Source: https://opensource.nibr.com/xgx/r/reference/xgx_conf_int This R code example demonstrates how to use the `xgx_conf_int` function with default settings for normally distributed data. It first creates a sample data frame with a 'y' column containing normally distributed values, then applies `xgx_conf_int` to calculate and display the mean, lower, and upper bounds of the 95% confidence interval for the 'y' data. ```R # default settings for normally distributed data, 95% confidence interval, data <- data.frame(x = rep(c(1, 2, 3), each = 20), y = rep(c(1, 2, 3), each = 20) + stats::rnorm(60), group = rep(1:3, 20)) xgx_conf_int(data$y) #> y ymin ymax #> 1 1.717784 1.382446 2.053123 ``` -------------------------------- ### Simulate Data Manipulation for Data Checking Source: https://opensource.nibr.com/xgx/Data_Checking This R code block demonstrates advanced data manipulation techniques, including modifying subject identifiers and creating a new categorical variable based on weight. Crucially, it also illustrates how to intentionally introduce a simulated patient with no PK or PD data, serving as an example for testing the robustness of data checking reports in identifying such edge cases. This specific simulation part is highlighted as being removable for actual production use. ```R data = data %>% mutate(USUBJID = paste0("PAT",USUBJID), WEIGHT0_CAT = case_when(WEIGHT0 < 60 ~ "WT<60", #creating 2nd categorical var WEIGHT0 > 80 ~ "WT>80", TRUE ~ "WT:60-80")) # a patient with no PK or PD data is added to the dataset to illustrate how the # data checking will report when such data is present. This code block should be # removed if you'll be using it with your dataset. empty_row = data[1,] %>% mutate(ID = 23, USUBJID = paste0("PAT",ID), LIDV = 0, YTYPE = 0, ADM = 1, CMT = 0, NAME = "Dose", EVENTU = "mg", UNIT = "mg", MDV = 1, CENS = 0, EVID = 1) data = bind_rows(data, empty_row) data1 = data %>% filter(!duplicated(USUBJID)) ``` -------------------------------- ### Setup R Environment for PD Data Analysis Source: https://opensource.nibr.com/xgx/Multiple_Ascending_Dose_PD_continuous This code block initializes the R environment by loading essential libraries for data manipulation, visualization, and specialized pharmacokinetic/pharmacodynamic (PK/PD) analysis. It also sets up global variables for draft status, configures the default ggplot theme, and defines directory paths for saving generated plots and scripts. ```R library(ggplot2) library(dplyr) library(tidyr) library(gridExtra) library(xgxr) #flag for labeling figures as draft status = "DRAFT" ## ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = tempdir(), rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### Example of xgx_theme_set with ggplot2 for concentration-response plot Source: https://opensource.nibr.com/xgx/r/reference/xgx_theme_set This example demonstrates how to use `xgx_theme_set` in conjunction with `ggplot2` to create a concentration-response plot. It generates sample concentration and bound receptor data, applies the `xgx` theme using `xgx_theme_set()`, and then constructs a plot using `ggplot2`'s `geom_point` and `geom_line`. Specialized axis scaling is applied using `xgx_scale_y_log10` and `xgx_scale_x_reverselog10` to handle logarithmic scales. The `xgx_theme_set()` call ensures the plot adheres to the standard `xgx` visual style. ```R conc <- 10^(seq(-3, 3, by = 0.1)) ecs50 <- 1 data <- data.frame(concentration = conc, bound_receptor = 1 * conc / (conc + ec50)) xgx_theme_set() ggplot2::ggplot(data, ggplot2::aes(y = concentration, x = bound_receptor)) + ggplot2::geom_point() + ggplot2::geom_line() + xgx_scale_y_log10() + xgx_scale_x_reverselog10() ``` -------------------------------- ### R Environment Setup for Binary Response Data Analysis Source: https://opensource.nibr.com/xgx/Multiple_Ascending_Dose_PD_binary This R code block initializes essential libraries for data manipulation and visualization, including `gridExtra`, `ggplot2`, `dplyr`, `xgxr`, and `tidyr`. It sets a random seed for reproducibility in plots with jitter, defines a 'DRAFT' status flag, applies custom ggplot settings using `xgx_theme_set()`, and configures directory paths for saving output graphs. This setup prepares the R environment for subsequent analysis and plotting of binary response data. ```R library(gridExtra) library(ggplot2) library(dplyr) library(xgxr) library(tidyr) #set seed for random number generator (for plots with jitter) set.seed(12345) #flag for labeling figures as draft status = "DRAFT" # ggplot settings xgx_theme_set() #directories for saving individual graphs dirs = list( parent_dir = "Parent_Directory", rscript_dir = "./", rscript_name = "Example.R", results_dir = "./", filename_prefix = "", filename = "Example.png") ``` -------------------------------- ### Basic Usage of xgx_theme Function Source: https://opensource.nibr.com/xgx/r/reference/xgx_theme Shows the basic call signature for the `xgx_theme` function, which applies a standard theme to xGx graphics. It takes no arguments and returns a ggplot2 compatible theme. ```R xgx_theme() ```