Published
Edited
Feb 29, 2020
Importers
Insert cell
Insert cell
studiesViz = {
const svg = d3.create('svg')
.attr('viewBox', [0, 0, width, height]);
const wrapper = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
// Create gradient
const defs = svg.append('defs');
/*const myGradient = defs.append('linearGradient')
.attr('id', 'mainGradient');
myGradient.append('stop')
.attr('offset', '0%')
.attr('stop-color', '#E3FCEC');
myGradient.append('stop')
.attr('offset', '100%')
.attr('stop-color', '#1F9D55');*/
wrapper.append('rect')
.attr('x', x(0))
.attr('width', x(0.2))
.attr('height', innerHeight)
.attr('fill', '#EFF8FF');
wrapper.append('rect')
.attr('x', x(0.2))
.attr('width', x(0.5))
.attr('height', innerHeight)
.attr('fill', '#BCDEFA');
wrapper.append('rect')
.attr('x', x(0.5))
.attr('width', x(0.3))
.attr('height', innerHeight)
.attr('fill', '#6CB2EB');
wrapper.append('rect')
.attr('x', x(0.8))
.attr('width', x(0.7))
.attr('height', innerHeight)
.attr('fill', '#3490DC');
wrapper.selectAll('text')
.data([[0.25, 'kleiner Effekt'], [0.53, 'mittlerer Effekt'], [0.85, 'großer Effekt']])
.join('text')
.attr('x', d => x(d[0]))
.attr('y', innerHeight - 10)
.text(d => d[1])
.style('font-size', 10)
.style('fill', '#0F2F21')
.style('font-weight', 'bold');
wrapper.append('g')
.call(grid);
wrapper.append('g')
.call(xAxis);
wrapper.append('g')
.call(yAxis);
wrapper.selectAll('circle')
.data(data)
.join('circle')
.attr('cx', d => x(d.effect))
.attr('cy', d => y(d.study) + y.bandwidth() / 2)
.attr('r', 5)
.attr('fill', '#0F2F21');
return svg.node();

}
Insert cell
height = 350
Insert cell
innerHeight = height - margin.top - margin.bottom
Insert cell
innerWidth = width - margin.left - margin.right
Insert cell
margin = ({bottom: 50, left: 250, top: 40, right: 40})
Insert cell
grid = g => g
.attr('stroke', '#3D4852')
.attr('stroke-opacity', 0.9)
.call(g => g.append('g')
.selectAll('line')
.data(data)
.join('line')
.attr('stroke-width', 2)
.attr('x1', x(x.domain()[0]))
.attr('x2', d => x(d.effect))
.attr('y1', d => y(d.study) + y.bandwidth() / 2)
.attr('y2', d => y(d.study) + y.bandwidth() / 2));
Insert cell
y.domain()
Insert cell
xAxis = g => g
.attr('transform', `translate(0,${innerHeight})`)
.call(d3.axisBottom(x).tickFormat(x => `d = ${x}`))
.call(g => g.selectAll('text')
.attr('font-size', 10))
.call(g => g.append("text")
.attr("x", innerWidth)
.attr("y", margin.bottom - 2)
.attr("fill", "currentColor")
.attr("text-anchor", "end")
.attr('font-weight', 'bold')
.attr('font-size', 12)
.text("Cohen's d"))
Insert cell
yAxis = g => g
.call(d3.axisLeft(y))
.call(g => g.select('.domain').remove())
.call(g => g.selectAll('.tick line')
.attr('stroke', '#3D4852')
.attr('stroke-width', 2))
.call(g => g.selectAll('text')
.data(data)
.attr('font-weight', d => {
return d.study == "Ward, Duke, Gneez, & Bos (2017)" ? "bold" : "normal"
})
.attr('font-size', '10px'));
Insert cell
x = d3.scaleLinear()
.domain([0, 1.5])
.range([0, innerWidth]);
Insert cell
y = d3.scaleBand()
.domain(data.map(d => d.study))
.range([innerHeight, 0]);
Insert cell
Insert cell
data = [{'study': 'Blasiman, Larabee, & Fabry (2018)',
'effect': 1.3},
{'study': 'Lee, Kim, McDonough, Mendoza, & Kim (2017)',
'effect': 0.45},
/*{'study': 'Seaborne & Fiorella (2018)',
'effect': 0.40},*/
{'study': 'Mendoza, Pody, Lee, Kim, & McDonough (2018)',
'effect': 0.14},
{'study': 'Froese et al. (2012)',
'effect': 0.84},
{'study': 'Thornton et al. (2014) - Hard Task',
'effect': 0.65},
{'study': 'Thornton et al. (2014) - Easy Task',
'effect': 0.20},
{'study': 'Thornton et al. (2014) - Trail Making Test A',
'effect': 0.08},
{'study': 'Thornton et al. (2014) - Trail Making Test B',
'effect': 0.74},
{'study': 'Ward, Duke, Gneez, & Bos (2017)',
'effect': 0.31}].sort((a,b) => (a.effect > b.effect) ? 1 : ((b.effect > a.effect) ? -1 : 0));
Insert cell
d3 = require('d3@5')
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