Faceted Plots Enhance Data Comparison

Layout plots help you split data into subsets and create multiple plots within a single chart. This technique allows you to display different views of your data side by side, making it simple to compare trends and patterns across groups. For example, if you are analyzing sales data by region, facets can generate separate plots for each region, providing clearer insights. Learn how using facets can improve your data analysis and storytelling.


Economist GGPlot Excel Paul Tol Black And White Solarized Stata Tableau Wall Street CanvasXpress
<html>

  <head>
    <!-- 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/dist/canvasXpress.min.js"></script>
  </head>

  <body>

    <!-- 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>

      // Use a data frame (2D-array) for the graph
      var data = [
        [ "Id", "Duration", "Discontinued", "Response", "Baseline", "Drug", "Code"],
        [ "Smp1", 4.8, null, 29.3, 192.7, "4 mg", "FL"],
        [ "Smp2", 33.9, null, 23, 175.1, "2 mg", "DLBCL"],
        [ "Smp3", 40.1, null, 19.6, 93.2, "3 F6 mg", "DLBCL"],
        [ "Smp4", 6.9, null, 14, 172, "4 mg", "FL"],
        [ "Smp5", 28.8, null, 5.2, 121.4, "3 F6 mg", "FL"],
        [ "Smp6", 40.5, 35.5, -1.4, 77.1, "3 F6 mg", "DLBCL"],
        [ "Smp7", 31.2, null, -2.8, 33.7, "2 mg", "DLBCL"],
        [ "Smp8", 40, 35, -6.9, 73.6, "2 mg", "DLBCL"],
        [ "Smp9", 41.8, null, -6.9, 188.6, "2 mg", "DLBCL"],
        [ "Smp10", 29.7, null, -7.1, 122.8, "2 mg", "DLBCL"],
        [ "Smp11", 1.5, null, -13.2, 80.8, "1 mg", "FL"],
        [ "Smp12", 10, 5, -13.9, 32.5, "4 F6 mg", "FL"],
        [ "Smp13", 45.5, null, -14.5, 183.4, "3 F6 mg", "FL"],
        [ "Smp14", 14.9, null, -16.6, 87.2, "4 F6 mg", "DLBCL"],
        [ "Smp15", 26.7, 21.7, -27.2, 43.5, "3 F6 mg", "FL"],
        [ "Smp16", 29.9, null, -33.9, 46.6, "2 mg", "DLBCL"],
        [ "Smp17", 5.6, 0.6, -43.5, 115.4, "2 mg", "DLBCL"],
        [ "Smp18", 10.7, null, -43.7, 99.9, "1 mg", "DLBCL"],
        [ "Smp19", 25.9, null, -51.4, 180.5, "3 F6 mg", "FL"],
        [ "Smp20", 20.8, null, -52.6, 130.3, "4 mg", "DLBCL" ]
      ];

      // Create the configuration for the graph
      var config = {
        "graphOrientation": "vertical",
        "graphType": "Bar",
        "layoutAdjust": true,
        "layoutConfig": [
          {
            "axisCoordinate": true,
            "graphType": "BarLine",
            "showDataValues": true,
            "xAxis": ["Duration"],
            "xAxis2": ["Discontinued"],
            "xAxisTitle": "Duration of Treatment"
          },
          {
            "colorBy": "Drug",
            "legendColumns": 5,
            "legendInside": true,
            "legendPosition": "bottomLeft",
            "showLegend": true,
            "showLegendTitle": false,
            "xAxisTitle": "Change from Baseline (%)"
          },
          {
            "barLollipopFactor": 1.5,
            "barLollipopOpen": false,
            "barType": "lollipop",
            "xAxisTitle": "Baseline (mm)"
          }
        ],
        "layoutTopology": "3X1",
        "showLegend": false,
        "stripBackgroundBorderColor": "rgba(0,0,0,0)",
        "stripShow": false,
        "stripTextColor": "rgb(0,0,0)",
        "title": "Tumor Response and Duration by Subject Id",
        "xAxis": ["Duration", "Discontinued", "Response", "Baseline"],
        "xAxis2Show": false
      }

      // Event used to create graph (optional)
      var events = false


      // Call the CanvasXpress function to create the graph
      var cX = new CanvasXpress("canvasId", data, config, events);

      // Functions after rendering graph
      cX.segregateVariables(["Panel"]);

    </script>

  </body>

</html>
<html>

  <head>
    <!-- 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/dist/canvasXpress.min.js"></script>
  </head>

  <body>

    <!-- 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" : {
            "Code" : ["FL","DLBCL","DLBCL","FL","FL","DLBCL","DLBCL","DLBCL","DLBCL","DLBCL","FL","FL","FL","DLBCL","FL","DLBCL","DLBCL","DLBCL","FL","DLBCL"],
            "Drug" : ["4 mg","2 mg","3 F6 mg","4 mg","3 F6 mg","3 F6 mg","2 mg","2 mg","2 mg","2 mg","1 mg","4 F6 mg","3 F6 mg","4 F6 mg","3 F6 mg","2 mg","2 mg","1 mg","3 F6 mg","4 mg"]
         },
         "y" : {
            "data" : [
              [4.8,33.9,40.1,6.9,28.8,40.5,31.2,40,41.8,29.7,1.5,10,45.5,14.9,26.7,29.9,5.6,10.7,25.9,20.8],
              [null,null,null,null,null,35.5,null,35,null,null,null,5,null,null,21.7,null,0.6,null,null,null],
              [29.3,23,19.6,14,5.2,-1.4,-2.8,-6.9,-6.9,-7.1,-13.2,-13.9,-14.5,-16.6,-27.2,-33.9,-43.5,-43.7,-51.4,-52.6],
              [192.7,175.1,93.2,172,121.4,77.1,33.7,73.6,188.6,122.8,80.8,32.5,183.4,87.2,43.5,46.6,115.4,99.9,180.5,130.3]
            ],
            "vars" : ["Duration","Discontinued","Response","Baseline"]
         },
         "z" : {
            "Panel" : [1,1,2,3]
         }
      }

      // Create the configuration for the graph
      var config = {
        "graphOrientation": "vertical",
        "graphType": "Bar",
        "layoutAdjust": true,
        "layoutConfig": [
          {
            "axisCoordinate": true,
            "graphType": "BarLine",
            "showDataValues": true,
            "xAxis": ["Duration"],
            "xAxis2": ["Discontinued"],
            "xAxisTitle": "Duration of Treatment"
          },
          {
            "colorBy": "Drug",
            "legendColumns": 5,
            "legendInside": true,
            "legendPosition": "bottomLeft",
            "showLegend": true,
            "showLegendTitle": false,
            "xAxisTitle": "Change from Baseline (%)"
          },
          {
            "barLollipopFactor": 1.5,
            "barLollipopOpen": false,
            "barType": "lollipop",
            "xAxisTitle": "Baseline (mm)"
          }
        ],
        "layoutTopology": "3X1",
        "showLegend": false,
        "stripBackgroundBorderColor": "rgba(0,0,0,0)",
        "stripShow": false,
        "stripTextColor": "rgb(0,0,0)",
        "title": "Tumor Response and Duration by Subject Id",
        "xAxis": ["Duration", "Discontinued", "Response", "Baseline"],
        "xAxis2Show": false
      }

      // Event used to create graph (optional)
      var events = false


      // Call the CanvasXpress function to create the graph
      var cX = new CanvasXpress("canvasId", data, config, events);

      // Functions after rendering graph
      cX.segregateVariables(["Panel"]);

    </script>

  </body>

</html>
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/r/cX-layoutContinuous-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/r/cX-layoutContinuous-smp.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
z=read.table("https://www.canvasxpress.org/data/r/cX-layoutContinuous-var.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
  data=y,
  smpAnnot=x,
  varAnnot=z,
  graphOrientation="vertical",
  graphType="Bar",
  layoutAdjust=TRUE,
  layoutConfig=list(list(axisCoordinate=1, graphType="BarLine", showDataValues=1, xAxis=list("Duration"), xAxis2=list("Discontinued"), xAxisTitle="Duration of Treatment"), list(colorBy="Drug", legendColumns=5, legendInside=1, legendPosition="bottomLeft", showLegend=1, showLegendTitle=0, xAxisTitle="Change from Baseline (%)"), list(barLollipopFactor=1.5, barLollipopOpen=0, barType="lollipop", xAxisTitle="Baseline (mm)")),
  layoutTopology="3X1",
  showLegend=FALSE,
  stripBackgroundBorderColor="rgba(0,0,0,0)",
  stripShow=FALSE,
  stripTextColor="rgb(0,0,0)",
  title="Tumor Response and Duration by Subject Id",
  xAxis=list("Duration", "Discontinued", "Response", "Baseline"),
  xAxis2Show=FALSE,
  afterRender=list(list("segregateVariables", list("Panel")))
)