Skip to content

Instantly share code, notes, and snippets.

@msund
Created January 1, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msund/7cb54021aeb5aed38555 to your computer and use it in GitHub Desktop.
Save msund/7cb54021aeb5aed38555 to your computer and use it in GitHub Desktop.
Benford's Law
install.packages("devtools") # so we can install from github
library("devtools")
install_github("ropensci/plotly") # plotly is part of ropensci
library(plotly)
py <- plotly(username="r_user_guide", key="mw5isa4yqp") # open plotly connection
library(ggplot2)
d <- 1:9
prob = log10(1 + (1/d))
benford_dist <- data.frame(type = "Benford", digit = 1:9, prob = prob)
q <- ggplot(benford_dist, aes(x = factor(digit), y = prob, fill = type))
q <- q + geom_bar(stat = "identity") + labs(title = "Benford's Law")
py$ggplotly()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment