Published
Edited
May 22, 2020
Fork of Hierarchies
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
render_data_table(data.slice(0, 10))
Insert cell
Insert cell
Insert cell
// Nest your data by type 1, then type 2
nested_data = d3
.nest()
.key(d => d['address'])
.key(a => a['room_type'])
.entries(data)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Structure your data as a hierarchy -- pass in an *object* whose *values* are your nested data
// To show each pokemon the same size, specify a `.sum` where each value is 1
hierarchy_Sunburst = d3
.hierarchy(
{ key: "Greater Seattle Area", values: nested_data },
d => d.values
)
.sum(d => +d.bedrooms)
Insert cell
// Create your own partition function: it can be the same as the one in the other notebook,
// But doesn't include the `d3.hierarchy` function (as we've already done that step)
my_partition = data => d3.partition().size([2 * Math.PI, 500])(data)
Insert cell
Insert cell
Insert cell
chart
Insert cell
md`## Tree Map
I ended up only selecting one key for nesting in Treemap because or else all the category will be too small to visualize.
`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart2.update()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
circlePacking
Insert cell
md`## Tree Diagram
Apparently my data set is not good for using tree diagram. If I list every unique value, about 6000 rows, my browser will not respond and recommend me to go into safe mode. So the best I could do is to display proerty options
`
Insert cell
tree_nested_data = d3
.nest()
.key(d => d['address'])
.key(a => a['room_type'])
.entries(data)
Insert cell
Insert cell
tree_formatted_Data = ({
name: 'Greater Seattle Area',
children: tree_nd
})
Insert cell
import { chart as chart4 } with {
tree_formatted_Data as data
} from '@d3/tidy-tree'
Insert cell
Insert cell
chart4
Insert cell
Insert cell
Insert cell
raw_data = d3.csvParse(await FileAttachment("Airbnb_Cleaned.csv").text())
Insert cell
data = raw_data.filter(
d => d.overall_satisfaction >= reviewSlider && d.price <= priceSlider
)
Insert cell
data.forEach(d => (d.address = d.address.split(",")[0]))
Insert cell
import {
displayCaution,
render_data_table,
table_styles
} from "@info474/utilities"
Insert cell
table_styles
Insert cell
_ = require('lodash')
Insert cell
d3 = require("d3@5")
Insert cell
height = 800
Insert cell
width = 800
Insert cell
format = d3.format(",d")
Insert cell
import { swatches, legend } from "@d3/color-legend"
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