Skip to content

Instantly share code, notes, and snippets.

@mbusigin
Last active August 29, 2015 13:57
Show Gist options
  • Save mbusigin/9381962 to your computer and use it in GitHub Desktop.
Save mbusigin/9381962 to your computer and use it in GitHub Desktop.
Combination Cumulative Distribution Function and Frequency Distribution graph.
cdf_pdf <- function(v, legend.loc="topleft", legend.cex=1, name="")
{
if ( name == "" )
{
name = names(v)[1]
}
a = as.vector(v)
lv = as.numeric(last(v))
hist(v, col="grey90", main="", xlab="", ylab="", )
p = par()
par(mar=c(3, 3, 1, 2) + 0.1)
par(new=T, xaxt="n", yaxt="n")
e = ecdf(a)
plot.ecdf(e, pch=16, cex=.5, xlab="", ylab="", main="")
points(lv, e(lv), pch=19, col="dodgerblue3")
par(xaxt="s", yaxt="s", mar=p$mar)
legend(legend.loc, c("Frequency (LHS)", paste(name, "CDF (RHS)"), paste("Present Value (RHS):", round(e(lv), 4))), col=c("grey90", "black", "dodgerblue3"), lty=c(NULL, 1, NULL), pch=c(15, 16, 16), cex=legend.cex)
axis(4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment