R/plot.R
plot_growth.Rd
Utility functions for adding growth standard bands to ggplot2/lattice plots
panel.who(
x,
x_var = "agedays",
y_var = "htcm",
sex = "Female",
p = c(1, 5, 25, 50),
color = NULL,
alpha = 0.15,
center = FALSE,
labels = TRUE,
x_trans = identity,
y_trans = identity
)
panel.igb(
gagebrth,
var = "lencm",
sex = "Female",
p = c(1, 5, 25, 50),
color = NULL,
alpha = 0.15,
center = FALSE,
labels = TRUE,
x_trans = identity,
y_trans = identity
)
panel.igfet(
gagedays,
var = "hccm",
p = c(1, 5, 25, 50),
color = "green",
alpha = 0.15,
center = FALSE,
labels = TRUE,
x_trans = identity,
y_trans = identity
)
geom_growthstandard(
mapping = NULL,
data = NULL,
x_seq,
x_var = "agedays",
y_var,
sex = "Female",
p = c(1, 5, 25, 50),
shade = NULL,
alpha = 0.15,
center = FALSE,
x_trans = identity,
y_trans = identity,
standard = "who",
inherit.aes = TRUE
)
geom_who(...)
geom_igb(..., var = "lencm")
geom_igfet(..., var = "hccm", color = "green")
value or vector of values that correspond to a measure defined by x_var
. x_seq
is used with geom_*
x variable name (typically "agedays")
y variable name (typically "htcm" or "wtkg")
"Male" or "Female"
centiles at which to draw the growth standard band polygons (only need to specify on one side of the median)
optional color to use for bands (will use sex
to determine if not specified). shade
is used with geom_*
transparency of the bands
should the bands be centered around the median?
should the centiles be labeled? (not implemented)
transformation function to be applied to x-axis
transformation function to be applied to y-axis
gestational age at birth in days (for igb plots)
variable name for y axis for igb or igfet plots ("lencm", "wtkg", or "hcircm" for igb; "accm", "bpdcm", "flcm", "hccm", or "ofdcm" for igfet)
gestational age in days (for igfet plots)
supplied direclty to ggplot2::layer
standard name to use. Either "who"
, "igb"
, or "igfet"
items supplied direclty to geom_growthstandard
if (FALSE) {
#### ggplot2
library(ggplot2)
p <- ggplot(data = subset(cpp, subjid == 8), aes(x = agedays, y = htcm)) +
geom_who(x_seq = seq(0, 2600, by = 10), y_var = "htcm") +
geom_point()
#### lattice
library(lattice)
xyplot(wtkg ~ agedays, data = subset(cpp, subjid == 8),
panel = function(x, y, ...) {
panel.who(x = seq(0, 2558, by = 30),
sex = "Male", y_var = "wtkg", p = 100 * pnorm(-3:0))
panel.xyplot(x, y, ...)
},
col = "black"
)
# look at Male birth lengths superposed on INTERGROWTH birth standard
# first we need just 1 record per subject with subject-level data
cppsubj <- subset(cpp, !duplicated(cpp$subjid))
xyplot(birthlen ~ jitter(gagebrth), data = subset(cppsubj, sex == "Male"),
panel = function(x, y, ...) {
panel.igb(gagebrth = 250:310, var = "lencm", sex = "Male")
panel.points(x, y, ...)
},
col = "black", alpha = 0.75,
xlab = "Gestational Age at Birth (days)", ylab = "Birth Length (cm)"
)
}