Published
Edited
Apr 3, 2020
1 fork
1 star
Insert cell
md`# Proportional Symbol Mapping of annual precipitation of China (mm)
-created by Geng Tian, the University of Iowa`
Insert cell
proportionalSymbols = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("path")
.datum(topojson.feature(basepolygons, basepolygons.objects.China_adm))
.attr("fill", "#ccc")
.attr("d", path_basemap);
svg.append("path")
.datum(topojson.mesh(basepolygons, basepolygons.objects.China_adm, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path_basemap);
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(150,600)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data([d3.min(percipitations_CHN), d3.max(percipitations_CHN)])
.join("g");
legend.append("circle")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("cy", d => -radius(d))
.attr("r", radius);
legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(format);
svg.append("g")
.attr("fill", "#7a0177")
.attr("fill-opacity", 0.5)
.attr("stroke", "#f768a1")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(points.features
.map(d => (d.value = d.properties.JS, d))
.sort((a, b) => b.value - a.value))
.join("circle")
.attr("transform", d => `translate(${path_points.centroid(d)})`)
.attr("r", d => radius(d.properties.JS))
.append("title")
.text(d => `${d.properties.NAME} : ${format(d.value)}`);
return svg.node();
}
Insert cell
height = 710
Insert cell
width = 975
Insert cell
projection = d3.geoTransverseMercator().rotate([-110,0]).fitExtent([[65, 80], [width, height]], China_p)
Insert cell
China_p = topojson.feature(basepolygons, basepolygons.objects.China_adm)
Insert cell
path_points = d3.geoPath().projection(projection);
Insert cell
path_basemap = d3.geoPath().projection(projection);
Insert cell
format = d3.format(".2s")
Insert cell
percipitations_CHN = []
Insert cell
points.features.forEach(d => percipitations_CHN.push(d.properties.JS))
Insert cell
//proportional symbols
radius = d3.scaleSqrt([d3.min(percipitations_CHN),d3.max(percipitations_CHN)], [3, 15])
Insert cell
//import the point data (geojson)
points = FileAttachment("chinarain_UTF-8.json").json("text/plain; charset=UTF-8")
Insert cell
//import the polygon base map data
basepolygons = FileAttachment("China_adm.json").json()
Insert cell
simple = require("simple-statistics@7.0.7/dist/simple-statistics.min.js")
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
/*
Spatial pattren of Chinese precipitation:
Precipitation are concentrated in south eastern part of China, and it decreases from south east to north west.
In the most north west or south west part of China (such as Xinjiang and Tibet), the annual precipitation is really low.
*/
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