Published
Edited
Apr 26, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
vega({
height: 500,
width: 500,
title: "Fitness changes",
layer: data.map(({ theta, label, color }) => vegaRadialLine(theta, { label, color }))
})
Insert cell
gamma = {
const sum_a = d3.sum(alphas);
const sum_a2 = d3.sum(alphas.map(a => a * a))
const sum_ab = d3.sum(alphas.map(a => a * (1 - a)))
return N * (sum_ab - sum_a2) / sum_a
}
Insert cell
data = {
const data = slopes.map((d, i) => ({
theta: Math.atan(d.value),
label: d.label,
color: d3.schemeCategory10[i],
}))
return data
}
Insert cell
slopes = [
{ value: 1, label: "individual - other-only" },
{ value: Infinity, label: "individual - whole-group" },
{ value: -1 / (N * alpha - 1), label: "group - other-only" },
{ value: -1 / (N * alpha), label: "group - whole-group" },
{ value: 1 / (gamma + 1), label: "multilevel - other-only" },
{ value: 1 / gamma, label: "multilevel - whole-group" },
]
Insert cell
alphas = d3.range(N).map(i => getAlpha_i())
Insert cell
function vegaRadialLine(theta, {
height = 200,
width = 300,
color = "red",
label = "",
} = {}) {
return {
title: label,
data: { values: [ { theta: PI/2 - theta, theta2: (PI/2 - theta) + 0.05, color, label, r: 1, r2: -1 } ] },
height,
width,
mark: {
type: "arc",
// stroke: color,
filled: true,
color,
},
encoding: {
radius: { field: "r", type: "quantitative", title: "Radius", "scale": {"domain": [0, 1]} },
radius2: { field: "r2", type: "quantitative", title: "Radius", "scale": {"domain": [0, 1]} },
theta: { field: "theta", type: "quantitative", title: "Theta", "scale": {"domain": [0, 2*PI]} },
theta2: { field: "theta2", type: "quantitative" },
// color: { field: "label", type: "nominal", range: ["green", "purple"],
// legend: { symbolType: "circle", symbolStrokeColor: color, symbolStrokeWidth: 4 } },
color: { field: "label" }
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more