legend.HazardShape {EstimationTools} | R Documentation |
Customize legend for plot.HazardShape
outputs
Description
Put legend after run plot.HazardShape
function.
Usage
legend.HazardShape(
x,
y = NULL,
legend = c("Empirical TTT", "Spline curve"),
fill = NULL,
col = 1,
border = "white",
lty = NA,
lwd = NA,
pch = c(1, NA),
angle = 45,
density = NULL,
bty = "o",
bg = par("bg"),
box.lwd = par("lwd"),
box.lty = par("lty"),
box.col = par("fg"),
pt.bg = NA,
cex = 1,
pt.cex = cex,
pt.lwd = lwd,
xjust = 0,
yjust = 1,
x.intersp = 1,
y.intersp = 1,
adj = c(0, 0.5),
text.width = NULL,
text.col = par("col"),
text.font = NULL,
merge = TRUE,
trace = FALSE,
plot = TRUE,
ncol = 1,
horiz = FALSE,
title = NULL,
inset = 0,
xpd = TRUE,
title.col = text.col[1],
title.adj = 0.5,
title.cex = cex[1],
title.font = text.font[1],
seg.len = 2,
curve_options = list(col = 2, lwd = 2, lty = 1)
)
Arguments
x , y |
the x and y co-ordinates to be used to position the legend.
They can be specified by keyword or in any way which is accepted by
|
legend |
a character or expression vector
of length |
fill |
if specified, this argument will cause boxes filled with the specified colors (or shaded in the specified colors) to appear beside the legend text. |
col |
the color of points or lines appearing in the legend. |
border |
the border color for the boxes (used only if
|
lty , lwd |
the line types and widths for lines appearing in the legend. One of these two must be specified for line drawing. |
pch |
the plotting symbols appearing in the legend, as
numeric vector or a vector of 1-character strings (see
|
angle |
angle of shading lines. |
density |
the density of shading lines, if numeric and
positive. If |
bty |
the type of box to be drawn around the legend. The allowed
values are |
bg |
the background color for the legend box. (Note that this is
only used if |
box.lty , box.lwd , box.col |
the line type, width and color for
the legend box (if |
pt.bg |
the background color for the |
cex |
character expansion factor relative to current
|
pt.cex |
expansion factor(s) for the points. |
pt.lwd |
line width for the points, defaults to the one for
lines, or if that is not set, to |
xjust |
how the legend is to be justified relative to the legend x location. A value of 0 means left justified, 0.5 means centered and 1 means right justified. |
yjust |
the same as |
x.intersp |
character interspacing factor for horizontal (x) spacing between symbol and legend text. |
y.intersp |
vertical (y) distances (in lines of text shared above/below each legend entry). A vector with one element for each row of the legend can be used. |
adj |
numeric of length 1 or 2; the string adjustment for legend
text. Useful for y-adjustment when |
text.width |
the width of the legend text in x ( |
text.col |
the color used for the legend text. |
text.font |
the font used for the legend text, see |
merge |
logical; if |
trace |
logical; if |
plot |
logical. If |
ncol |
the number of columns in which to set the legend items (default is 1, a vertical legend). |
horiz |
logical; if |
title |
a character string or length-one expression giving a
title to be placed at the top of the legend. Other objects will be
coerced by |
inset |
inset distance(s) from the margins as a fraction of the plot region when legend is placed by keyword. |
xpd |
if supplied, a value of the graphical parameter |
title.col |
color for |
title.adj |
horizontal adjustment for |
title.cex |
expansion factor(s) for the title, defaults to |
title.font |
the font used for the legend title, defaults to |
seg.len |
the length of lines drawn to illustrate |
curve_options |
a list whose names are curve graphical parameters, and whose values are the corresponding graphical parameters values. |
Details
This function is a wrapper for the legend
function.
It just adds two features:
-
legend
has a default value, regarding thatHazardShape
objects produces the TTT plot and its LOESS estimation. -
curve_options
is used to set legend parameters for the LOESS curve. We encourage you to define first a list with curve parameters, and then pass it toplot.HazardShape
andlegend.HazardShape
(see example 2).
Author(s)
Jaime Mosquera GutiƩrrez jmosquerag@unal.edu.co
Examples
library(EstimationTools)
data("reduction_cells")
TTT_IG <- TTTE_Analytical(Surv(days, status) ~ 1, data = reduction_cells,
method = 'censored')
HS_IG <- TTT_hazard_shape(TTT_IG, data = reduction_cells)
#----------------------------------------------------------------------------
# Example 1: put legend to the TTT plot of the reduction cells data set.
# Run `plot.HazardShape` method.
par(
cex.lab=1.8,
cex.axis=1.8,
mar=c(4.8,5.4,1,1),
las = 1,
mgp=c(3.4,1,0)
)
plot(HS_IG, pch = 16, cex = 1.8)
# Finally, put the legend
legend.HazardShape(
x = "bottomright",
box.lwd = NA,
cex = 1.8,
pt.cex = 1.8,
bty = 'n',
pch = c(16, NA)
)
#----------------------------------------------------------------------------
# Example 2: example 1 with custom options for the curve
# This is the list with curve parameters
loess_options <- list(
col = 3, lwd = 4, lty = 2
)
par(
cex.lab=1.8,
cex.axis=1.8,
mar=c(4.8,5.4,1,1),
las = 1,
mgp=c(3.4,1,0)
)
plot(HS_IG, pch = 16, cex = 1.8, curve_options = loess_options)
legend.HazardShape(
x = "bottomright",
box.lwd = NA,
cex = 1.8,
pt.cex = 1.8,
bty = 'n',
pch = c(16, NA),
curve_options = loess_options
)