Public
Edited
May 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
margin = ({top: 30, right: 30, bottom: 30, left: 50});
Insert cell
height = 300
Insert cell
viewof n = {
const form = html`<form style="font: 12px var(--sans-serif); display: flex; align-items: center; min-height: 33px;">
<label style="display: block;">
<input name="input" type="range" min="1" max="50" value="12" step="1" style="width: 180px;">
n = <output name="output"></output>
</label>
</form>`;
form.oninput = () => form.output.value = form.value = form.input.valueAsNumber;
form.oninput();
return form;
}
Insert cell
data = d3.tsvParse(await FileAttachment("data_test@2.tsv").text())
Insert cell
shapes = d3.scaleOrdinal(data.map(d => d.Condition), d3.symbols.map(s => d3.symbol().type(s).size(64)()))
Insert cell
//xScale = d3.scaleLinear().range([0, width]);
xScale = d3.scaleLinear()
.domain(d3.extent(data, d => d.posx)).nice()
.range([margin.left, width - margin.right])
Insert cell
//yScale = d3.scaleLinear().range([height, 0]);
yScale = d3.scaleLinear()
.domain(d3.extent(data, d => d.posy)).nice()
.range([height - margin.bottom, margin.top])
Insert cell
xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(xScale).ticks(width / 80))
//.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", width)
.attr("y", margin.bottom - 4)
.attr("fill", "currentColor")
.attr("text-anchor", "end")
.text(data.posx))
Insert cell
yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(yScale))
//.call(g => g.select(".domain").remove())
.call(g => g.append("text")
.attr("x", -margin.left)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text(data.posy))
Insert cell
//keys = [];
Insert cell
variable2 = [];
Insert cell
data.forEach(function(d){
d.posx = +d.posx;
d.posy = +d.posy;
if(keys.indexOf(d.TimePoint) == -1){
keys.push(d.TimePoint);
console.log(d.TimePoint);
}
if(variable2.indexOf(d.Condition) == -1){
variable2.push(d.Condition);
}
d.highlight = false;
});
Insert cell
keys = ["v3", "v2"]
Insert cell
fillColors = [
"#0000CD", "#00FF00", "#00FF00", "#FF0000", "#808080", "#000000", "#B22222", "#DAA520",
"#DDA0DD", "#FF00FF", "#00FFFF", "#4682B4", "#E6E6FA", "#FF8C00", "#80008B", "#8FBC8F",
"#00BFFF", "#FFFF00", "#808000", "#FFCCCC", "#FFE5CC", "#FFFFCC", "#E5FFCC", "#CCFFCC"]
Insert cell
// set the colors
zScale = d3.scaleOrdinal()
.range(fillColors).domain(keys);
Insert cell
//zScale = d3.scaleOrdinal(data.map(d => d.TimePoint), d3.schemeCategory10)
zScale.domain()
Insert cell
data.map(d => d.TimePoint)
Insert cell
Insert cell
d3 = require("d3@6")
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