Documentation for `get_histogram_barplot` function
Source:vignettes/get_histogram_barplot.Rmd
      get_histogram_barplot.RmdPurpose
The get_histogram_barplot function is designed to
generate a bar plot displaying liver-related scores, based on data
either provided directly or fetched from an SQLite database. It
calculates mean values for specific findings, compares liver-related and
non-liver-related groups, and produces either a plot or a processed data
frame depending on the function’s parameters.
Input Parameters
The function accepts the following parameters:
| Parameter | Type | Description | 
|---|---|---|
Data | 
data.frame, optional | 
A data frame containing liver-related scores. If NULL,
the function will attempt to generate or fetch data from a database or
file. | 
generateBarPlot | 
logical, default = FALSE
 | 
Flag indicating whether to generate a bar plot. If
TRUE, a bar plot is generated; otherwise, the function
returns a data frame. | 
path_db | 
character, optional | 
Path to the SQLite database if data needs to be fetched from it.
Required if use_xpt_file is FALSE or
fake_study is FALSE. | 
rat_studies | 
logical, default = FALSE
 | 
Flag to specify whether to filter for rat studies when fetching data from the database. | 
studyid_metadata | 
data.frame, required | 
Metadata associated with the study IDs. Needed when
fake_study is FALSE and real data is
fetched. | 
fake_study | 
logical, default = FALSE
 | 
If TRUE, the function simulates study data instead of
fetching it from a database. | 
use_xpt_file | 
logical, default = FALSE
 | 
If TRUE, the function will use an XPT file to fetch
data, instead of relying on the database. | 
Round | 
logical, default = FALSE
 | 
Whether to round the liver scores. If TRUE, scores are
rounded. | 
output_individual_scores | 
logical, default = TRUE
 | 
Whether to output individual scores or aggregated ones. | 
output_zscore_by_USUBJID | 
logical, default = FALSE
 | 
Whether to output z-scores by USUBJID (unique subject identifier). | 
Output
If
generateBarPlot = TRUE: The function returns aggplot2bar plot object displaying the average scores for liver-related findings versus non-liver-related findings.If
generateBarPlot = FALSE: The function returns adata.frame(plotData) containing the calculated values for each finding, with columns for the finding, liver status (LIVER), and mean values (Value).
Key Steps
- 
Data Generation/Fallback:
- If no data is provided, the function attempts to fetch the data from an SQLite database or use a fake study dataset.
 - It fetches study data from the 
dmdomain of the database iffake_study = FALSE. The study IDs are then extracted, filtered for liver-related studies, and used for subsequent score calculations. 
 - 
Data Harmonization:
- The 
get_liver_om_lb_mi_tox_score_listfunction calculates liver scores for the provided study IDs. - The resulting data is harmonized using
get_col_harmonized_scores_dfto ensure consistency in the output data frame. 
 - The 
 - 
Plot Generation:
- If 
generateBarPlot = TRUE, the function iterates over the findings and computes the average liver-related score (Liverstatus) for each finding. - It then generates a 
ggplot2bar plot with the findings on the x-axis, the average values on the y-axis, and distinct colors representing liver vs. non-liver status. 
 - If 
 - 
Error Handling:
- The function checks whether the 
Dataparameter is a valid data frame. If not, an error is thrown. 
 - The function checks whether the