R/plot_all_NG_biomarkers.R
plot_all_NG_biomarkers.Rd
Save a forestplot of all Nightingale biomarker associations in a 2-page,
predefined layout (utilizes forestplot
).
plot_all_NG_biomarkers( df, machine_readable_name = machine_readable_name, name = NULL, estimate = estimate, se = se, pvalue = NULL, colour = NULL, shape = NULL, logodds = FALSE, psignif = 0.05, ci = 0.95, filename = NULL, paperwidth = 15, paperheight = sqrt(2) * paperwidth, xlims = NULL, layout = "2020", ... )
df | A data frame with the data to plot. It must contain at least three
variables, a character column with the names to be displayed on the y-axis
(see parameter |
---|---|
machine_readable_name | the variable in df containing the machine
readable names of Nightingale blood biomarkers. I.e. the names in this
variable must be the same as in the |
name | the variable in |
estimate | the variable in |
se | the variable in the |
pvalue | the variable in |
colour | the variable in |
shape | the variable in |
logodds | logical (defaults to FALSE) specifying whether the |
psignif | numeric, defaults to 0.05. The p-value threshold
for statistical significance. Entries with larger than |
ci | A number between 0 and 1 (defaults to 0.95) indicating the type of confidence interval to be drawn. |
filename | a character string giving the name of the file. |
paperwidth | page width in inches |
paperheight | page height in inches |
xlims | NULL or a numeric vector of length 2 specifying the common x limits across all biomarker subgroups. |
layout | one of the predefined layouts in |
... |
|
If filename is NULL, a list of plot objects (one for each page in layout) is returned.
The function uses a custom grouping specified by
df_grouping_all_NG_biomarkers
. The input df
and
df_grouping_all_NG_biomarkers
are joined by machine_readable_name
,
while another df
variable may be used for y-axis labels, defined in
name
input parameter.
if (FALSE) { # Join the built-in association demo dataset with a variable that contains # the machine readable names of Nightingale biomarkers. (Note: if you # have built your association data frame using the Nightingale CSV result file, # then your data frame should already contain machine readable names.) df <- df_linear_associations %>% left_join( select( df_NG_biomarker_metadata, name, machine_readable_name ), by = "name" ) # Print effect sizes for Nightingale biomarkers in a 2-page pdf plot_all_NG_biomarkers( df = df, machine_readable_name = machine_readable_name, # Notice that when name is not defined explicitly, names from # df_NG_biomarker_metadata are used estimate = beta, se = se, pvalue = pvalue, colour = trait, filename = "biomarker_linear_associations.pdf", xlab = "1-SD increment in BMI per 1-SD increment in biomarker concentration", layout = "2016" ) # Custom layout can also be provided layout <- df_NG_biomarker_metadata %>% dplyr::filter( .data$group == "Fatty acids", .data$machine_readable_name %in% df$machine_readable_name ) %>% dplyr::mutate( group_custom = .data$subgroup, column = dplyr::case_when( .data$group_custom == "Fatty acids" ~ 1, .data$group_custom == "Fatty acid ratios" ~ 2 ), page = 1 ) %>% dplyr::select( .data$machine_readable_name, .data$group_custom, .data$column, .data$page ) plot_all_NG_biomarkers( df = df, machine_readable_name = machine_readable_name, # Notice that when name is not defined explicitly, names from # df_NG_biomarker_metadata are used estimate = beta, se = se, pvalue = pvalue, colour = trait, xlab = "1-SD increment in BMI per 1-SD increment in biomarker concentration", layout = layout ) # log odds for type 2 diabetes df <- df_logodds_associations %>% left_join( select( df_NG_biomarker_metadata, name, machine_readable_name ), by = "name" ) %>% # Set the study variable to a factor to preserve order of appearance # Set class to factor to set order of display. dplyr::mutate( study = factor( study, levels = c("Meta-analysis", "NFBC-1997", "DILGOM", "FINRISK-1997", "YFS") ) ) # Print effect sizes for Nightingale biomarkers in a 2-page pdf plot_all_NG_biomarkers( df = df, machine_readable_name = machine_readable_name, # Notice that when name is not defined explicitly, names from # df_NG_biomarker_metadata are used estimate = beta, se = se, pvalue = pvalue, colour = study, logodds = TRUE, filename = "biomarker_t2d_associations.pdf", xlab = "Odds ratio for incident type 2 diabetes (95% CI) per 1−SD increment in metabolite concentration", layout = "2016", # Restrict limits as some studies are very weak and they take over the # overall range. xlims = c(0.5, 3.2) ) }