Description Usage Arguments Examples
View source: R/06-tree-plot-function.r
This function produces a tree plot showing the treatment effect size of subgroups defined by the categories of covariates. The left side shows treatment effect size; the right side indicates what covariate is considered. Each level shows the 95 effect estimate and subgroup sample sizes (by the width of horizontal violet lines). Each subgroup is further divided into several subgroups by categories of the covariate on the lower level. The horizontal line corresponding to the overal effect can be added into each level so as to check homogeneity across subgroup effects with repective to the overall effect. In addition, the function uses log odd ratio and log hazard ratio for displaying subgroup effect sizes in binary and survival data, respectively.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
dat |
a data set |
covari.sel |
a vector of indices of the two covariates |
trt.sel |
a covariate index specifying the treatment code |
resp.sel |
a covariate index specifying the response variable |
outcome.type |
a string specifying the type of the response variable, it can be "continuous", or "binary" or "survival". |
add.aux.line |
a logical operator displaying the auxiliary horizontal line for checking heterogeneity in treatment effects if TRUE |
font.size |
a vector specifying the size of labels and text; the first element is for the main title and the second element is for the text in the left, right and bottom labels; the third is for the unit labels on the y-axis. |
title |
a string specifying the main title. |
lab.y |
a string specifying the y-axis label |
text.shift |
a numeric indicating the separation of the text in the branches |
keep.y.axis |
a logical indicating whether to keep the y axis fixed across the levels |
grid.newpage |
logical. If TRUE (default), the function calls grid::grid.newpage() to start from an empty page. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | library(dplyr)
# Load the data to be used
data(prca)
dat <- prca
dat %>%
mutate(bm = factor(ifelse(bm == 0 , "No", "Yes")),
hx = factor(ifelse(hx == 0 , "No", "Yes"))) -> dat
## Tree plot with fixed y-axis
plot_tree(dat,
covari.sel = c(4, 5, 7),
trt.sel = 3,
resp.sel = c(1, 2),
outcome.type = "survival",
add.aux.line = TRUE,
font.size = c(12, 8, 0.55),
title = NULL,
lab.y = "Effect size (log hazard ratio)",
keep.y.axis = TRUE)
## Tree plot with free y-axes
plot_tree(dat,
covari.sel = c(4, 5, 7),
trt.sel = 3,
resp.sel = c(1, 2),
outcome.type = "survival",
add.aux.line = TRUE,
font.size = c(12, 8, 0.55),
title = NULL,
lab.y = "Effect size (log hazard ratio)",
keep.y.axis = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.