100% stacked smooth area: composition by age

Area graphs provide an excellent way to showcase changes in quantity over time. They are particularly useful for visualizing trends and comparing the magnitude of different categories within a dataset. Unlike line graphs, area graphs emphasize the cumulative value of each category, making them suitable for depicting proportions or totals. Common applications include financial data, website traffic analysis, and population demographics. The filled area beneath the line helps highlight the overall volume or quantity involved, making it easier to identify significant increases or decreases. Effective area graphs use clear legends, distinct colors, and appropriate labels for enhanced readability.


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 = 

      // Create the configuration for the graph
      var config = {
         "graphType" : "Area",
         "graphOrientation" : "vertical",
         "theme" : "ggplot",
         "areaType" : "percent",
         "lineType" : "spline",
         "xAxis" : [
            "Actinobacteria",
            "Bacteroidetes",
            "Firmicutes",
            "Proteobacteria",
            "Other"
         ],
         "colorScheme" : "User",
         "colors" : [
            "#EE7733",
            "#0077BB",
            "#009988",
            "#CC3311",
            "#BBBBBB"
         ],
         "objectColorTransparency" : 0.8,
         "title" : "Gut microbiome composition in the first three years",
         "smpTitle" : "Age (months)",
         "smpLabelInterval" : 3,
         "smpTextRotate" : 90,
         "xAxisTitle" : "Relative abundance (%)",
         "showLegend" : true,
         "legendPosition" : "top",
         "legendColumns" : 5,
         "decorations" : {
            "marker" : [
               {
                  "text" : "Solid food\nintroduced",
                  "variable" : "Firmicutes",
                  "sample" : "12",
                  "type" : "arrow",
                  "x" : 0.397,
                  "y" : 0.0538
               }
            ]
         },
         "source" : "Synthetic data for illustration"
      }

      // 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);

    </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 = {
         "y" : {
            "vars" : [
               "Actinobacteria",
               "Bacteroidetes",
               "Firmicutes",
               "Proteobacteria",
               "Other"
            ],
            "smps" : [
               "0",
               "2",
               "4",
               "6",
               "8",
               "10",
               "12",
               "14",
               "16",
               "18",
               "20",
               "22",
               "24",
               "26",
               "28",
               "30",
               "32",
               "34",
               "36"
            ],
            "data" : [
               [
                  55.4,
                  53.5,
                  50.5,
                  46.1,
                  40.2,
                  32.8,
                  24.8,
                  17,
                  14.9,
                  13.5,
                  12.6,
                  12.2,
                  12.1,
                  12.5,
                  13.1,
                  13.9,
                  14.7,
                  15.3,
                  15.6
               ],
               [
                  3.6,
                  5.4,
                  7.4,
                  9.6,
                  12.5,
                  16.2,
                  20.6,
                  25.2,
                  28,
                  30.3,
                  32.2,
                  33.6,
                  34.4,
                  34.6,
                  34.3,
                  33.7,
                  33.2,
                  33,
                  33
               ],
               [
                  10.8,
                  13.6,
                  17,
                  21.3,
                  26.5,
                  32.4,
                  38.1,
                  42.9,
                  44,
                  44.2,
                  43.9,
                  43.4,
                  42.8,
                  42.3,
                  41.9,
                  41.7,
                  41.4,
                  41.1,
                  40.8
               ],
               [
                  27.2,
                  24.2,
                  21.4,
                  18.9,
                  16.5,
                  14.2,
                  12.1,
                  10.4,
                  8.8,
                  7.6,
                  6.9,
                  6.4,
                  6.1,
                  5.9,
                  5.7,
                  5.6,
                  5.4,
                  5.3,
                  5.1
               ],
               [
                  3,
                  3.4,
                  3.7,
                  4,
                  4.3,
                  4.4,
                  4.4,
                  4.5,
                  4.3,
                  4.3,
                  4.3,
                  4.4,
                  4.6,
                  4.8,
                  5,
                  5.2,
                  5.3,
                  5.5,
                  5.5
               ]
            ]
         }
      }

      // Create the configuration for the graph
      var config = {
         "graphType" : "Area",
         "graphOrientation" : "vertical",
         "theme" : "ggplot",
         "areaType" : "percent",
         "lineType" : "spline",
         "xAxis" : [
            "Actinobacteria",
            "Bacteroidetes",
            "Firmicutes",
            "Proteobacteria",
            "Other"
         ],
         "colorScheme" : "User",
         "colors" : [
            "#EE7733",
            "#0077BB",
            "#009988",
            "#CC3311",
            "#BBBBBB"
         ],
         "objectColorTransparency" : 0.8,
         "title" : "Gut microbiome composition in the first three years",
         "smpTitle" : "Age (months)",
         "smpLabelInterval" : 3,
         "smpTextRotate" : 90,
         "xAxisTitle" : "Relative abundance (%)",
         "showLegend" : true,
         "legendPosition" : "top",
         "legendColumns" : 5,
         "decorations" : {
            "marker" : [
               {
                  "text" : "Solid food\nintroduced",
                  "variable" : "Firmicutes",
                  "sample" : "12",
                  "type" : "arrow",
                  "x" : 0.397,
                  "y" : 0.0538
               }
            ]
         },
         "source" : "Synthetic data for illustration"
      }

      // 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);

    </script>

  </body>

</html>
library(canvasXpress)
y=read.table("https://www.canvasxpress.org/data/r/cX-area18-dat.txt", header=TRUE, sep="\t", quote="", row.names=1, fill=TRUE, check.names=FALSE, stringsAsFactors=FALSE)
canvasXpress(
data=y,
areaType="percent",
colorScheme="User",
colors=list("#EE7733", "#0077BB", "#009988", "#CC3311", "#BBBBBB"),
decorations=list(marker=list(list(sample=12, text="Solid food\nintroduced", type="arrow", variable="Firmicutes", x=0.397, y=0.0538))),
graphOrientation="vertical",
graphType="Area",
legendColumns=5,
legendPosition="top",
lineType="spline",
objectColorTransparency=0.8,
showLegend=TRUE,
smpLabelInterval=3,
smpTextRotate=90,
smpTitle="Age (months)",
source="Synthetic data for illustration",
theme="ggplot",
title="Gut microbiome composition in the first three years",
xAxis=list("Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"),
xAxisTitle="Relative abundance (%)"
)
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import show_in_browser

if __name__ == "__main__":
  # Define the chart with its data and configuration
  chart: CanvasXpress = CanvasXpress(
    render_to = "area18",
    data = {
      "y": {
        "vars": ["Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"],
        "smps": ["0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36"],
        "data": [
          [55.4, 53.5, 50.5, 46.1, 40.2, 32.8, 24.8, 17, 14.9, 13.5, 12.6, 12.2, 12.1, 12.5, 13.1, 13.9, 14.7, 15.3, 15.6],
          [3.6, 5.4, 7.4, 9.6, 12.5, 16.2, 20.6, 25.2, 28, 30.3, 32.2, 33.6, 34.4, 34.6, 34.3, 33.7, 33.2, 33, 33],
          [10.8, 13.6, 17, 21.3, 26.5, 32.4, 38.1, 42.9, 44, 44.2, 43.9, 43.4, 42.8, 42.3, 41.9, 41.7, 41.4, 41.1, 40.8],
          [27.2, 24.2, 21.4, 18.9, 16.5, 14.2, 12.1, 10.4, 8.8, 7.6, 6.9, 6.4, 6.1, 5.9, 5.7, 5.6, 5.4, 5.3, 5.1],
          [3, 3.4, 3.7, 4, 4.3, 4.4, 4.4, 4.5, 4.3, 4.3, 4.3, 4.4, 4.6, 4.8, 5, 5.2, 5.3, 5.5, 5.5]
        ]
      }
    },
    config = {
      "graphType": "Area",
      "graphOrientation": "vertical",
      "theme": "ggplot",
      "areaType": "percent",
      "lineType": "spline",
      "xAxis": ["Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"],
      "colorScheme": "User",
      "colors": ["#EE7733", "#0077BB", "#009988", "#CC3311", "#BBBBBB"],
      "objectColorTransparency": 0.8,
      "title": "Gut microbiome composition in the first three years",
      "smpTitle": "Age (months)",
      "smpLabelInterval": 3,
      "smpTextRotate": 90,
      "xAxisTitle": "Relative abundance (%)",
      "showLegend": True,
      "legendPosition": "top",
      "legendColumns": 5,
      "decorations": {
        "marker": [
          {
            "text": "Solid food\nintroduced",
            "variable": "Firmicutes",
            "sample": "12",
            "type": "arrow",
            "x": 0.397,
            "y": 0.0538
          }
        ]
      },
      "source": "Synthetic data for illustration"
    },
    width = 760,
    height = 560
  )

  # Display the chart in its own Web page
  show_in_browser(chart)
Run this notebook: Open in Binder
from canvasxpress.canvas import CanvasXpress
from canvasxpress.plot import graph

graph(
  CanvasXpress(
    render_to = "area18",
    data = {
      "y": {
        "vars": ["Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"],
        "smps": ["0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36"],
        "data": [
          [55.4, 53.5, 50.5, 46.1, 40.2, 32.8, 24.8, 17, 14.9, 13.5, 12.6, 12.2, 12.1, 12.5, 13.1, 13.9, 14.7, 15.3, 15.6],
          [3.6, 5.4, 7.4, 9.6, 12.5, 16.2, 20.6, 25.2, 28, 30.3, 32.2, 33.6, 34.4, 34.6, 34.3, 33.7, 33.2, 33, 33],
          [10.8, 13.6, 17, 21.3, 26.5, 32.4, 38.1, 42.9, 44, 44.2, 43.9, 43.4, 42.8, 42.3, 41.9, 41.7, 41.4, 41.1, 40.8],
          [27.2, 24.2, 21.4, 18.9, 16.5, 14.2, 12.1, 10.4, 8.8, 7.6, 6.9, 6.4, 6.1, 5.9, 5.7, 5.6, 5.4, 5.3, 5.1],
          [3, 3.4, 3.7, 4, 4.3, 4.4, 4.4, 4.5, 4.3, 4.3, 4.3, 4.4, 4.6, 4.8, 5, 5.2, 5.3, 5.5, 5.5]
        ]
      }
    },
    config = {
      "graphType": "Area",
      "graphOrientation": "vertical",
      "theme": "ggplot",
      "areaType": "percent",
      "lineType": "spline",
      "xAxis": ["Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"],
      "colorScheme": "User",
      "colors": ["#EE7733", "#0077BB", "#009988", "#CC3311", "#BBBBBB"],
      "objectColorTransparency": 0.8,
      "title": "Gut microbiome composition in the first three years",
      "smpTitle": "Age (months)",
      "smpLabelInterval": 3,
      "smpTextRotate": 90,
      "xAxisTitle": "Relative abundance (%)",
      "showLegend": True,
      "legendPosition": "top",
      "legendColumns": 5,
      "decorations": {
        "marker": [
          {
            "text": "Solid food\nintroduced",
            "variable": "Firmicutes",
            "sample": "12",
            "type": "arrow",
            "x": 0.397,
            "y": 0.0538
          }
        ]
      },
      "source": "Synthetic data for illustration"
    },
    width = 760,
    height = 560
  )
)
using CanvasXpress

canvasxpress(Dict(
  "y" => Dict(
    "vars" => ["Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"],
    "smps" => ["0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36"],
    "data" => [
      [55.4, 53.5, 50.5, 46.1, 40.2, 32.8, 24.8, 17, 14.9, 13.5, 12.6, 12.2, 12.1, 12.5, 13.1, 13.9, 14.7, 15.3, 15.6],
      [3.6, 5.4, 7.4, 9.6, 12.5, 16.2, 20.6, 25.2, 28, 30.3, 32.2, 33.6, 34.4, 34.6, 34.3, 33.7, 33.2, 33, 33],
      [10.8, 13.6, 17, 21.3, 26.5, 32.4, 38.1, 42.9, 44, 44.2, 43.9, 43.4, 42.8, 42.3, 41.9, 41.7, 41.4, 41.1, 40.8],
      [27.2, 24.2, 21.4, 18.9, 16.5, 14.2, 12.1, 10.4, 8.8, 7.6, 6.9, 6.4, 6.1, 5.9, 5.7, 5.6, 5.4, 5.3, 5.1],
      [3, 3.4, 3.7, 4, 4.3, 4.4, 4.4, 4.5, 4.3, 4.3, 4.3, 4.4, 4.6, 4.8, 5, 5.2, 5.3, 5.5, 5.5]
    ]
  )
);
  graphType = "Area",
  graphOrientation = "vertical",
  theme = "ggplot",
  areaType = "percent",
  lineType = "spline",
  xAxis = ["Actinobacteria", "Bacteroidetes", "Firmicutes", "Proteobacteria", "Other"],
  colorScheme = "User",
  colors = ["#EE7733", "#0077BB", "#009988", "#CC3311", "#BBBBBB"],
  objectColorTransparency = 0.8,
  title = "Gut microbiome composition in the first three years",
  smpTitle = "Age (months)",
  smpLabelInterval = 3,
  smpTextRotate = 90,
  xAxisTitle = "Relative abundance (%)",
  showLegend = true,
  legendPosition = "top",
  legendColumns = 5,
  decorations = Dict(
    "marker" => [
      Dict(
        "text" => "Solid food\nintroduced",
        "variable" => "Firmicutes",
        "sample" => "12",
        "type" => "arrow",
        "x" => 0.397,
        "y" => 0.0538
      )
    ]
  ),
  source = "Synthetic data for illustration"
)
⇧