lhist: Histogram with logged x-axis

Description Usage Arguments Details Value Examples

View source: R/hello.R

Description

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.

Usage

1
lhist(x)

Arguments

x

Numeric vector

Details

Currently, this visualization is the one I find the most useful:

Value

A ggplot-object.

Examples

 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)

FelixTheStudent/ggpower documentation built on March 5, 2020, 8:37 p.m.