Box Plots in Nodejs

How to make a box plot in nodejs. Seven examples of box plots in nodejs that are grouped, colored, and display the underlying data distribution.


Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.

// Learn about API authentication here: https://plotly.com/nodejs/getting-started
// Find your api_key here: https://plotly.com/settings/api

for (var i = 0; i < 50; i ++) {
	y0[i] = Math.random();
	y1[i] = Math.random() + 1;
}

require('plotly')(username, api_key);

var trace1 = {
  y: y0,
  type: "box"
};
var trace2 = {
  y: y1,
  type: "box"
};
var data = [trace1, trace2];
var graphOptions = {filename: "basic-box-plot", fileopt: "overwrite"};
plotly.plot(data, graphOptions, function (err, msg) {
    console.log(msg);
});
// Learn about API authentication here: https://plotly.com/nodejs/getting-started
// Find your api_key here: https://plotly.com/settings/api

require('plotly')(username, api_key);

var data = [
  {
    y: [0, 1, 1, 2, 3, 5, 8, 13, 21],
    boxpoints: "all",
    jitter: 0.3,
    pointpos: -1.8,
    type: "box"
  }
];
var graphOptions = {filename: "box-plot-jitter", fileopt: "overwrite"};
plotly.plot(data, graphOptions, function (err, msg) {
    console.log(msg);
});
// Learn about API authentication here: https://plotly.com/nodejs/getting-started
// Find your api_key here: https://plotly.com/settings/api

var x = ['day 1', 'day 1', 'day 1', 'day 1', 'day 1', 'day 1',
         'day 2', 'day 2', 'day 2', 'day 2', 'day 2', 'day 2']

require('plotly')(username, api_key);

var trace1 = {
  y: [0.2, 0.2, 0.6, 1.0, 0.5, 0.4, 0.2, 0.7, 0.9, 0.1, 0.5, 0.3],
  x: x,
  name: "kale",
  marker: {color: "#3D9970"},
  type: "box"
};
var trace2 = {
  y: [0.6, 0.7, 0.3, 0.6, 0.0, 0.5, 0.7, 0.9, 0.5, 0.8, 0.7, 0.2],
  x: x,
  name: "radishes",
  marker: {color: "#FF4136"},
  type: "box"
};
var trace3 = {
  y: [0.1, 0.3, 0.1, 0.9, 0.6, 0.6, 0.9, 1.0, 0.3, 0.6, 0.8, 0.5],
  x: x,
  name: "carrots",
  marker: {color: "#FF851B"},
  type: "box"
};
var data = [trace1, trace2, trace3];
var layout = {
  yaxis: {
    title: "normalized moisture",
    zeroline: false
  },
  boxmode: "group"
};
var graphOptions = {layout: layout, filename: "box-grouped", fileopt: "overwrite"};
plotly.plot(data, graphOptions, function (err, msg) {
    console.log(msg);
});