# Simple distribution plot in R

July 2, 2012
By

(This article was first published on Digital Hardcore » rbloggers, and kindly contributed to R-bloggers)

Plot the distribution of a sample as bars and add a histogram line for visualizing the sample characteristics.

`##' Plot distribution of a sample with bars, lines and rug.##' @title ##' @param x ##' @return ##' @author Dimtiris Kavroudakis, [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */, www.dimitrisk.grplotDistribution = function (x) {  N = length(x)  hist( x,col = "light blue",        probability = TRUE)  lines(density(x), col = "red", lwd = 3)  rug(x)} x = c(3,4,4,4,7,5,5,5,6,8,4,2)plotDistribution(x)`

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...