lin-log transition histogram

Description

Draw histograms that gradually transform from a linear to a logarithmic axis (animation)

Usage

1
2
3
4
5
linLogHist(x, steps = 100, breaks = 20, col = "blue", las = 1,
  xlab = deparse(substitute(x)), xlim = range(x, finite = TRUE),
  box = TRUE, parexpr, endexpr, sleep = 0, axisargs = NULL,
  axisargs2 = NULL, firstplot = TRUE, lastplot = TRUE, write_t = TRUE,
  values_t = NULL, ...)

Arguments

x

x values to be plotted in animation

steps

Number of steps in transition. DEFAULT: 100

breaks

hist breaks. DEFAULT: 20

col

hist color. DEFAULT: "blue"

las

par LabelAxisStyle (numbers upright). DEFAULT: 1

xlab

Label for the x axis. DEFAULT: deparse(substitute(x))

xlim

xlim range in non-log units. DEFAULT: range(x, finite=TRUE)

box

Draw box at the end to overplot ablines crossing the box? DEFAULT: TRUE

parexpr

Characterized Expression to set par, eg. parexpr='par(mar=c(2,0.5,1.5,0.5), mpg=c(1.8,1,0))'

endexpr

Characterized Expression executed at the end of the plot, eg. endexpr='mtext("Probability Density", line=-1, adj=0.03, outer=T)'

sleep

Pause time between frames, in seconds, passed to Sys.sleep. DEFAULT: 0

axisargs

List of arguments passed to logVals, like base. DEFAULT: NULL

axisargs2

List of arguments passed to logAxis in the final plot. DEFAULT: NULL

firstplot

plot on linear scale first? DEFAULT: TRUE

lastplot

plot on logarithmic scale at the end? DEFAULT: TRUE

write_t

write transformation value in lower right corner? DEFAULT: TRUE

values_t

Supply vector with values for transformation (1/t). Overides steps. If you have a better algorithm than I do, please let me know! DEFAULT: NULL

...

further arguments passed to hist, like freq, main, xlim, ylab. Excluded: x, xaxt, possibly add

Value

Returned invisibly: transformation values used. Plotted: steps number of images.

Note

It's best to save the plots into a pdf or wrap it within
png("Transition%03d"); linLogHist(x); dev.off()

Author(s)

Berry Boessenkool, berry-b@gmx.de, April 2015

See Also

linLogTrans

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
x <- rlnorm(700, m=3)
hist(x, col=4)
hist(log10(x), xaxt="n"); logAxis(1); hist(log10(x), col=4, add=TRUE)

op <- par()
linLogHist(x, steps=8, sleep=0.01) # 0.05 might be smoother

linLogHist(x, xlab="ddd", breaks=30, steps=3, write_t=FALSE, yaxt="n", freq=FALSE,
   main="", parexpr='par(mar=c(2,0.5,1.5,0.5), mgp=c(1.8,1,0))',
   endexpr='mtext("Probability Density", line=-1.2, adj=0.03, outer=T)')
par(op)

## Not run: 
## Rcmd check --as-cran doesn't like to open external devices such as pdf,
## so this example is excluded from running in the checks.
pdf("LinLogTransitionAnimation.pdf")
linLogHist(x, main="Example Transition", steps=20, freq=FALSE)
dev.off()

# if you have FFmpeg installed, you can use the animation package like this:
library2(animation)
saveVideo(linLogHist(x, steps=50), video.name="linlog_anim.mp4", interval=0.08,
ffmpeg="C:/ffmpeg-20150424-git-cd69c0e-win64-static/bin/ffmpeg.exe")

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.