Unlisted
Edited
Mar 15, 2024
Insert cell
Insert cell
viewof table = Inputs.table(diamonds)
Insert cell
Removed in parent
viewof x = Inputs.select(["depth","table","price"], {value: "depth", multiple: false, label: "X axis"})
Insert cell
Removed in parent
viewof y = Inputs.select(["depth","table","price"], {value: "table", multiple: false, label: "Y axis"})
Insert cell
viewof col = Inputs.select(Object.keys(diamonds[0]).sort(), {value: "cut", multiple: false, label: "Color variable"})

Insert cell
colorType = Plot.dot(table, {fill:col, filter:[]}).plot().scale("color").type
Insert cell
Changed in parent
Plot.plot({ color: { legend: true, ...(colorType === "ordinal" ? { range: [ "green", "purple", "orange", "yellow", "blue", "pink", "brown", "grey", "green", "lavender" ] } : { scheme: "blues" }) }, marks: [ Plot.dot(diamonds, {
-
x: "depth", y: "table",
+
x: x, y: y,
stroke: col, tip: true, channels: { Color: "color", Clarity: "clarity" } }) ], grid: true })
Insert cell
Added in parent
This solution allows to manually specify both categorical color palette and and a continuous color scheme when the color variable is not known in advance.
Insert cell