Description Usage Arguments Examples
View source: R/02-contour-plot-function.r
this function produces a contour plot showing the treatment effect size of subgroups. The subgroups are first defined by certain ranges of the first continuous covariate; and then further divided into smaller subgroup by certain ranges of the second covariate . The subgroups over the first covariate have a sample size close to one pre-specified value (N2) and any neighboring subgroups have an overlap size near the second pre-specified value (N1). Similarly, each subgroup over the first covariate has a sample size near the third pre-specified value (N4), and any neighboring subgroups which are further divided over the second covariate have a sample size near the fourth pre-specified value (N3). The x-coordinate and y-coordinate of a point indicates the middle point of the range over the first covariate and that over the second covariate, respectively. The contours show approximate effect sizes which are obtained by fitting grid points over the polynormial surface interpolating the points corresponding to subgroups.Note that there are three parameters for controlling the setting of contours. In addition, the function uses log odd ratio and log hazard ratio for displaying subgroup effect sizes in binary and survival data, respectively. Also, the actual subgroup sample sizes over the covariates are shown on the console window.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | plot_contour(
dat,
covari.sel,
trt.sel,
resp.sel,
outcome.type,
setup.ss,
n.grid = c(41, 41),
brk.es = c(0, 1, 2, 3),
n.brk.axis = 7,
para.plot = c(0.35, 2, 20),
font.size = c(1.5, 1.2, 1, 0.85, 0.8),
title = NULL,
subtitle = "default",
effect = "HR",
point.size = 1.2,
filled = FALSE,
strip = NULL,
show.overall = FALSE,
palette = "divergent",
col.power = 0.5,
show.points = FALSE,
new.layout = TRUE
)
|
dat |
a data set |
covari.sel |
a vector of indices of the two covariates |
trt.sel |
a variable index specifying the treatment code |
resp.sel |
a variable index specifying the response variable |
outcome.type |
a string specifying the type of the response variable, it can be "continuous", or "binary" or "survival". |
setup.ss |
a vector specifying approximate subgroup sample size and neibourghing subgroup overlap sample size. The first and the second elements are for overlap sizes and subgroup sample sizes over the first covariate; the third and thefourth are for further divided overlap sizes and subgroup sample sizes over the second covariate. |
n.grid |
a vector specifying the numbers of the grid points on the x-axis and the y-axis respectively. |
brk.es |
a vector specifying the break points on effect size, where each range partition is given with a different colour on points. |
n.brk.axis |
a number specifying the number of breakpoints dividing the axis of the argument "range.strip". |
para.plot |
a vector specifying the parameters of the contour plot; the first value is for controlling the degree of smoothing; the second is for controlling the degree of the polynomials fitting to be used (normally 1 or 2); the third is for controlling the number of contour lines. |
font.size |
a vector specifying the size of labels and text; the first element is for the main title, the second is for for x-axis and y-axis labels; the third is for the subtitle; the fourth is for the text in the legend; the fifth is for the labels on contour lines. |
title |
a string specifying the main title. |
subtitle |
strings specifying the subtitle |
effect |
either "HR" or "RMST". only when outcome.type = "survival" |
point.size |
size of points for raw data points |
filled |
a logical indicator whether to show filled contour plot. If FALSE, contour lines are drawn |
strip |
the title for the strip showing treatment effect size |
show.overall |
logical. whether to show or not the overall treatment effect in the strip |
palette |
either "divergent" or "hcl" |
col.power |
to be used when palette = "hcl". see colorspace package for reference |
show.points |
a logical indicator specifying whether to show the raw data points |
new.layout |
logical. If TRUE (default), the function calls graphics::layout(matrix(c(1, 2), nrow=1, ncol=2), widths=c(4,1)) 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 | library(dplyr)
# Load the data to be used
data(prca)
dat <- prca
setup.ss = c(10,60,15,30)
sub.title = bquote(N[11] %~~% .(setup.ss[2]) ~", "~
N[12] %~~% .(setup.ss[1]) ~", "~
N[21] %~~% .(setup.ss[4]) ~", "~
N[22] %~~% .(setup.ss[3]))
dat %>%
rename(Weight = weight,
Age = age) -> dat
plot_contour(dat,
covari.sel = c(8,9),
trt.sel = 3,
resp.sel = c(1,2),
outcome.type = "survival",
setup.ss = setup.ss,
n.grid = c(100,100),
brk.es = seq(-4.5,4.5,length.out = 101),
n.brk.axis = 7,
para.plot = c(0.5, 2, 6),
font.size = c(1, 1, 1, 1, 1),
title = NULL,
subtitle = sub.title,
strip = paste("Treatment effect size (log hazard ratio)"),
show.overall = TRUE,show.points = TRUE,
filled = TRUE, palette = "hcl",col.power = 0.75)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.