spikecomp | R Documentation |
Compute Elements of a Spike Histogram
spikecomp(
x,
method = c("tryactual", "simple", "grid"),
lumptails = 0.01,
normalize = TRUE,
y,
trans = NULL,
tresult = c("list", "segments", "roundeddata")
)
x |
a numeric variable |
method |
specifies the binning and output method. The default is |
lumptails |
the quantile to use for lumping values into a single left and a single right bin for two of the methods. When outer quantiles using |
normalize |
set to |
y |
a vector of frequencies corresponding to |
trans |
a list with three elements: the name of a transformation to make on |
tresult |
applies only to |
Derives the line segment coordinates need to draw a spike histogram. This is useful for adding elements to ggplot2
plots and for the describe
function to construct spike histograms. Date/time variables are handled by doing calculations on the underlying numeric scale then converting back to the original class. For them the left endpoint of the first bin is taken as the minimal data value instead of rounded using pretty()
.
when y
is specified, a list with elements x
and y
. When method='tryactual'
the returned value depends on tresult
. For method='grid'
, a list with elements x
and y
and scalar element roundedTo
containing the typical bin width. Here x
is a character string.
Frank Harrell
spikecomp(1:1000)
spikecomp(1:1000, method='grid')
## Not run:
On a data.table d use ggplot2 to make spike histograms by country and sex groups
s <- d[, spikecomp(x, tresult='segments'), by=.(country, sex)]
ggplot(s) + geom_segment(aes(x=x, y=y1, xend=x, yend=y2, alpha=I(0.3))) +
scale_y_continuous(breaks=NULL, labels=NULL) + ylab('') +
facet_grid(country ~ sex)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.