Description Usage Arguments Details Value Examples
Useful e.g. for log-normal distributions, etc.. Wraps
ggplot+geom_histogram with all the things I usually get wrong (see details)
Type lhist to see code for copy-pasting.
1 | lhist(x)
|
x |
Numeric vector |
Currently, this visualization is the one I find the most useful:
x-axis is log10-transformed (coord_trans, !not! scale_x - otherwise, adding theoretical probability density distributions does not work)
log10-spaced bins, otherwise coord_trans throws error and/or bin widths look extremely uneven
y-axis is sqrt-transformed, otherwise you don't see higher values so well (play around with the example below and you'll see)
add x-labels with +xlab("var_name") and
theoretical distributions with
geom_line(aes(logseq(x), dlnorm(x, meanlog, sdlog)))
A ggplot-object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Not run:
if(interactive()){
#EXAMPLE1
x <- rlnorm(100000, meanlog = c(-6,.4), sdlog = 1)
xseq <- pmax(1e-5, exp(seq(log(.9*min(x)), log(1.1*max(x)), length.out = 100)))
# with lhist function:
lhist(x)+
geom_line(aes(xseq, .5*dlnorm(xseq, -6, 1)), color="blue") +
geom_line(aes(xseq, .5*dlnorm(xseq, .4, 1)), color="red")
# without lhist function (slightly more typing):
ggplot()+
geom_histogram(data=data.frame(x=x), aes(x, stat(density)), breaks=xseq) +
geom_line(aes(xseq, .5*dlnorm(xseq, -6, 1)), color="blue") +
geom_line(aes(xseq, .5*dlnorm(xseq, .4, 1)), color="red") +
coord_trans(x="log", y="sqrt")
}
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.