The open source JavaScript graphing library that powers Plotly

Show Sidebar Hide Sidebar

Groupby in plotly.js

How to use D3.js-based Group By in Plotly.js.

var subject = ['Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly','Moe','Larry','Curly']
var score = [1,6,2,8,2,9,4,5,1,5,2,8]

var data = [{
  type: 'scatter',
  x: subject,
  y: score,
  mode: 'markers',
  transforms: [{
    type: 'groupby',
    groups: subject,
    styles: [
      {target: 'Moe', value: {marker: {color: 'blue'}}},
      {target: 'Larry', value: {marker: {color: 'red'}}},
      {target: 'Curly', value: {marker: {color: 'black'}}}

Plotly.plot('graph', data)
Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.