Histogram Chart

A histogram takes as input a numeric variable only. The variable is cut into several bins, and the number of observation per bin is represented by the height of the bar. It is possible to represent the distribution of several variable on the same axis using this technique.



Color Themes


{
   "m" : {
      "Description" : "Average weekly household spending, in British pounds, on tobacco products and alcoholic beverages for each of the 11 regions of Great Britain.",
      "Name" : "Alcohol Tobacco",
      "Reference" : "Moore, David S., and George P. McCabe (1989). Introduction to the Practice of Statistics, p. 179. Original source  :  Family Expenditure Survey, Department of Employment, 1981 (British official statistics)"
   },
   "x" : {
      "Description" : ["Average weekly household spending on alcoholic beverages in pounds","Average weekly household spending on tobacco products in pounds"]
   },
   "y" : {
      "data" : [
        [6.47,4.03],
        [6.13,3.76],
        [6.19,3.77],
        [4.89,3.34],
        [5.63,3.47],
        [4.52,2.92],
        [5.89,3.2],
        [4.79,2.71],
        [3.53,3.53],
        [6.08,4.51],
        [4.02,4.56]
      ],
      "smps" : ["Alcohol","Tobacco"],
      "vars" : ["North","Yorkshire","Northeast","East Midlands","West Midlands","East Anglia","Southeast","Southwest","Wales","Scotland","Northern Ireland"]
   }
}
{
   "citation" : "Moore, David S., and George P. McCabe (1989). Introduction to the Practice of Statistics, p. 179.",
   "decorations" : {
      "marker" : [{"sample" : ["Alcohol","Tobacco"],
            "text" : "Maybe an Outlier?",
            "variable" : "Northern Ireland",
            "x" : 0.45,
            "y" : 0.18
         }
      ]
   },
   "graphType" : "Scatter2D",
   "histogramBins" : "20",
   "showTransition" : "false",
   "theme" : "CanvasXpress",
   "title" : "Average weekly household spending, in British pounds, on tobacco products\\nand alcoholic beverages for each of the 11 regions of Great Britain.",
   "xAxisTitle" : "Pounds Spent",
   "yAxisTitle" : "Frequency"
}
var cX = CanvasXpress.$("canvasId");
cX.createHistogram();
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/cX-alcoholtobaccot-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
x=read.table("https://www.canvasxpress.org/data/cX-alcoholtobaccot-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
  data=y,
  smpAnnot=x,
  citation="Moore, David S., and George P. McCabe (1989). Introduction to the Practice of Statistics, p. 179.",
  decorations=list(marker=list(list(sample=list("Alcohol", "Tobacco"), text="Maybe an Outlier?", variable="Northern Ireland", x=0.45, y=0.18))),
  graphType="Scatter2D",
  histogramBins=20,
  showTransition=FALSE,
  theme="CanvasXpress",
  title="Average weekly household spending, in British pounds, on tobacco products\nand alcoholic beverages for each of the 11 regions of Great Britain.",
  xAxisTitle="Pounds Spent",
  yAxisTitle="Frequency",
  afterRender=list(list("createHistogram"))
)