Published
Edited
Sep 13, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
md `## Strip/Jitter Plot.`
Insert cell
Insert cell
new Array(oneDdata.length).fill(1)
Insert cell
viewof jitterScale = slider()
Insert cell
Insert cell
stripPlotData = {
const data = new Array(oneDdata.length).fill(0);
if ( jitter=="true") return data.map(d=>jitterScale*(Math.random()-0.5));
else return data;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
binSize = {
const xExtent = dataExtent;
return (xExtent[1]-xExtent[0])/nBins
}
Insert cell
xAxisLabel = dim==='eruptions'?'Eruption Duration':'Waiting Time'
Insert cell
dataExtent = d3.extent(oneDdata);
Insert cell
oneDdata = extract(dim)
Insert cell
densityDataLength = 100
Insert cell
delta = (dataExtent[1]-dataExtent[0])/densityDataLength
Insert cell
densityX = new Array(densityDataLength+1).fill(0).map((d,i)=>dataExtent[0]+i*delta)
Insert cell
kernel = kernels[kernelname](bandWidth)
Insert cell
densityY = kde(kernel,densityX,oneDdata)
Insert cell
function kde(kernel, Xs, data) {
return Xs.map(x => d3.mean(data, d => kernel(Math.abs(x - d)/bandWidth)/bandWidth));
}
Insert cell
Insert cell
oldFaithful = d3.csvParse(await FileAttachment("faithful.csv").text(), d3.autoType);
Insert cell
extract = attribute=>oldFaithful.map(d=>d[attribute]);
Insert cell
//import {epanechnikov} from "@d3/kernel-density-estimation"
Insert cell
kernels = ({
cosine: () => (x => x <= 1 ? (Math.PI/4)*Math.cos(x*Math.PI/2): 0),
epanechnikov: () => (x => x <= 1 ? (3/4) * (1 - x * x) : 0),
quartic: () => (x => x <= 1 ? (15/16)*((1 - x * x)**2) : 0),
triweight: () => (x => x <= 1 ? (35/32)*((1 - x * x)**3) : 0),
tricube: () => (x => x <= 1 ? (35/32)*((1 - x**3)**3) : 0),
uniform:() => (x => x <= 1 ? 0.5 : 0),
triangle: () => (x => x <= 1 ? (1 - x): 0)
})
// Chosen Kernels with finite extent from https://en.wikipedia.org/wiki/Kernel_(statistics)
// Note all the kernels are symmetric and are zero outside the range -1 to + 1.
// So input to these functions are values that are translated and scaled so that it is zero at the peak value of the function.
Insert cell
Plotly = require("plotly.js-dist") //require("https://cdn.plot.ly/plotly-latest.min.js")
Insert cell
import {radio, slider} from "@jashkenas/inputs"
Insert cell
md`## D3 Based visualization`
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more