Lollipop Chart

A lollipop plot is basically a barplot, where the bar is transformed in a line and a dot. It shows the relationship between a numeric and a categoric variable. However it is more appealing and convey as well the information. It is especially useful when you have several bars of the same height: it avoids to have a cluttered figure and a Moiré effect. The Cleveland dot plot is a handy variation, allowing to compare the value of 2 numeric values for each group.


Example Color Themes

Example Fonts



Show Code

Tools

<!-- Include the CanvasXpress library in your HTML file -->
<link rel="stylesheet" href="https://www.canvasxpress.org/dist/canvasXpress.css" type="text/css"/>
<script src="https://www.canvasxpress.org/canvasXpress.min.js"></script>


<!-- Create a canvas element for the chart with the desired dimensions -->
<div>
  <canvas id="canvasId" width="600" height="600"</canvas>
</div>


<!-- Create a script to initialize the chart -->
<script>

  <!-- Create the data for the graph -->
  var data = {
     "x" : {
        "Color" : ["A","B","C","D","E","F"]
     },
     "y" : {
        "data" : [
          [-40,-85,-60,50,75,100]
        ],
        "smps" : ["Engineering","Biology","Computer","Psycology","Education","Health"],
        "vars" : ["Var1"]
     }
  }
  
  
  <-- Create the configuration for the graph -->
  var config = {
     "backgroundType":"solid",
     "barLollipopFactor":1.5,
     "barLollipopOpen":"true",
     "barPath":"true",
     "barPathColor":"rgb(225,225,225)",
     "barPathTransparency":"1",
     "barType":"lollipop",
     "colorBy":"Color",
     "colorScheme":"GGPlot",
     "graphType":"Bar",
     "marginBottom":"50",
     "marginLeft":"50",
     "marginRight":"50",
     "marginTop":"50",
     "maxTextSize":"80",
     "objectBorderColor":"rgba(255,255,255,0)",
     "setMaxX":"150",
     "setMinX":"-150",
     "showDataValues":"true",
     "showLegend":"false",
     "smpLabelScaleFontFactor":"2",
     "title":"Occupations",
     "xAxis2Show":"false",
     "xAxisShow":"false",
     "xAxisTicksMajorShow":"false",
     "xAxisTicksMinorShow":"false"
  }
  

  <!-- Call the CanvasXpress function to create the graph -->
  var cX = new CanvasXpress("canvasId", data, config);


</script>
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/cX-lollipop2-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-lollipop2-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
  data=y,
  smpAnnot=x,
  backgroundType="solid",
  barLollipopFactor=1.5,
  barLollipopOpen=TRUE,
  barPath=TRUE,
  barPathColor="rgb(225,225,225)",
  barPathTransparency=1,
  barType="lollipop",
  colorBy="Color",
  colorScheme="GGPlot",
  graphType="Bar",
  marginBottom=50,
  marginLeft=50,
  marginRight=50,
  marginTop=50,
  maxTextSize=80,
  objectBorderColor="rgba(255,255,255,0)",
  setMaxX=150,
  setMinX=-150,
  showDataValues=TRUE,
  showLegend=FALSE,
  smpLabelScaleFontFactor=2,
  title="Occupations",
  xAxis2Show=FALSE,
  xAxisShow=FALSE,
  xAxisTicksMajorShow=FALSE,
  xAxisTicksMinorShow=FALSE
)