Viewing a saved revision (read-only)
2HkKY6I5Zpe3uHx0v_qAI
Created from react-d3-starter template
React D3 Starter
A minimal React + D3 starter for building interactive data visualizations.
Files
index.html— page shell and import map (React + D3 from a CDN).index.jsx— mounts the<App />component.App.jsx— loadsdata.csvand renders the visualization.viz.js— D3 render entry point.renderCircles.js— draws the circles.useContainerDimensions.js— tracks the container size.data.csv— sample data.styles.css— page styles.
Getting started
Edit App.jsx to change what gets rendered; the preview updates live as you type.
Visualization Ideas
Notes for all ideas: the data is data/part-d-state-specialty-2024.csv (state x specialty, 50 states + DC). Costs are gross of rebates. Suppressed generic values are excluded, not imputed, so rows missing generic_claims or generic_drug_cost_usd should be dropped from generic-based metrics. Brand figures are derived: brand claims = total_claims − generic_claims, and brand cost = total_drug_cost_usd − generic_drug_cost_usd. Always load the CSV at runtime with the existing parseCsvText.
Claims vs. Cost Gap Slope Chart
- Question: How far does brand share of cost exceed brand share of claims nationally and in each specialty?
- Fields:
specialty,total_claims,generic_claims,total_drug_cost_usd,generic_drug_cost_usd. - Encoding: For each specialty, a slope line from brand share of claims (left axis) to brand share of cost (right axis). Line color encodes gap size.
- Interaction: Hover highlights a specialty. Annotate the largest gaps.
- Implementation: Use
d3.rollupby specialty, sum the numerators and denominators, then compute the shares. Don't average the row-level shares.
National Claims vs. Cost Stacked Bars
- Question: Do brand drugs dominate spending while generics dominate claims?
- Fields:
total_claims,generic_claims,total_drug_cost_usd,generic_drug_cost_usd. - Encoding: Two 100% horizontal stacked bars (claims, cost), split into brand and generic.
- Interaction: Annotate the percentages directly on the segments.
- Implementation: Sum across all rows with valid generic values. Use
d3.stackor two rects per bar.
Specialty Gap Dumbbell Plot
- Question: Which specialties have the widest gap between brand cost share and brand claim share?
- Fields:
specialty,brand_share_of_claims,brand_share_of_cost,total_claims. - Encoding: Rows sorted by gap, with two dots per row joined by a line. Dot size is claim volume.
- Interaction: Toggle the sort between gap and claim volume.
- Implementation: Weighted aggregation by specialty. Use a band scale for the y axis.
State × Specialty Heatmap of Brand Cost Share
- Question: Where do brand cost shares run high or low across states and specialties?
- Fields:
state_code,specialty,brand_share_of_cost. - Encoding: Grid of rects with a sequential color scale. Missing cells show as hatched gray.
- Interaction: Hover for a tooltip. Click a column header to sort states by that specialty.
- Implementation: Order rows by region, then by state. Use
scaleSequential(interpolateBlues).
Regional Small Multiples of the Gap
- Question: Does the claims/cost gap pattern differ across Census regions?
- Fields:
census_region,specialty,brand_share_of_claims,brand_share_of_cost. - Encoding: One scatter panel per region, with x = brand claim share and y = brand cost share. Draw a y = x reference diagonal.
- Interaction: Shared brushing across panels highlights the same specialty everywhere.
- Implementation: Facet with
d3.group. Use the same scales in every panel.
State Tile-Grid Map
- Question: Which states have the largest overall brand cost share, and are there regional clusters?
- Fields:
state_code,census_region,total_drug_cost_usd,generic_drug_cost_usd. - Encoding: A tile grid with one square per state (including DC), colored by brand cost share. Outline color is the region.
- Interaction: A dropdown filters by specialty. Click a tile to pin the state.
- Implementation: Hardcode the grid layout as a layout lookup keyed by
state_code. No data values are hardcoded.
Beeswarm of State Gaps by Specialty
- Question: How much do states vary within a given specialty?
- Fields:
specialty,state_code,brand_share_of_cost,census_region. - Encoding: One horizontal beeswarm lane per specialty, colored by region.
- Interaction: Hover labels the state. Click a state to highlight it across all lanes.
- Implementation: Use
d3.forceSimulationwith forceX and forceCollide, precomputed statically.
Region Boxplots of Brand Cost Share
- Question: Is variation larger between regions or within them?
- Fields:
census_region,brand_share_of_cost,specialty. - Encoding: Box plots per region with jittered points overlaid.
- Interaction: A specialty filter dropdown.
- Implementation: Compute quartiles with
d3.quantile.
Cost-per-Claim Ridgeline by Specialty
- Question: How does the cost per claim distribution differ across specialties?
- Fields:
specialty,cost_per_claim_usd. - Encoding: Ridgelines on a log x scale, ordered by median.
- Interaction: Hover marks the median and quartiles.
- Implementation: Use
d3.binwith log-spaced thresholds, or a kernel density estimate computed in log space.
Existing Scatter Upgrade: Brand Share Encoding
- Question: Do high cost-per-claim, low-volume groups also have high brand cost share?
- Fields:
total_claims,cost_per_claim_usd,provider_records,brand_share_of_cost. - Encoding: Keep the current log-log bubble chart but color by
brand_share_of_cost(sequential). Region moves to the outline or a facet. - Interaction: Legend brushing, plus specialty filter chips.
- Implementation: Extend
renderPoints.js. Addbrand_share_of_costcolor scale and a legend gradient.
Generic Cost vs. Brand Cost Scatter
- Question: How does brand spending scale with generic spending?
- Fields:
generic_drug_cost_usd,total_drug_cost_usd,specialty. - Encoding: Log-log scatter of brand cost (total − generic) against generic cost, colored by specialty. Add a reference line for equal spend.
- Interaction: Hover for details. Click a legend item to isolate a specialty.
- Implementation: Derive brand cost and drop rows where it is ≤ 0 (log scale).
Treemap of Brand Spending
- Question: Which specialties and states account for the most brand-drug dollars?
- Fields:
specialty,state,total_drug_cost_usd,generic_drug_cost_usd. - Encoding: Treemap by specialty, then state. Area is brand cost and color is brand cost share.
- Interaction: Click to zoom into a specialty.
- Implementation: Build with
d3.hierarchyandd3.treemap.
Pareto Curve of Brand Spending
- Question: How concentrated is brand spend in a few specialties?
- Fields:
specialty, brand cost (derived). - Encoding: Sorted bars with a cumulative-percent line on a secondary axis.
- Interaction: Annotate where the cumulative share crosses 80%.
- Implementation: Use
d3.cumsumon the sorted totals.
Parallel Coordinates for State Profiles
- Question: Which states resemble each other across several metrics?
- Fields: Per state, brand share of claims, brand share of cost, cost per claim, claims per provider (
total_claims/provider_records). - Encoding: Polylines colored by region.
- Interaction: Axis brushing filters states. Hover highlights a line.
- Implementation: Aggregate by state with weighted sums. Use a linear scale per axis.
Claims per Provider vs. Cost per Claim
- Question: Does prescribing intensity relate to cost intensity across specialties?
- Fields:
total_claims,provider_records,cost_per_claim_usd,specialty. - Encoding: Scatter of claims per provider (x) against cost per claim (y), with a faint trend line per specialty.
- Interaction: Brush to list the selected points in a side table.
- Implementation: Derive claims per provider. Use
d3.brushand render the list in React.
Region × Specialty Gap Bar Matrix
- Question: Which specialty-region combinations show the largest gaps?
- Fields:
census_region,specialty, brand cost share and brand claim share (derived). - Encoding: A matrix whose cells hold a diverging bar, brand cost share minus brand claim share.
- Interaction: Hover shows the actual shares.
- Implementation: Aggregate with
d3.rollupon a composite region/specialty key.
Ranked Lollipop of States
- Question: Which states lead or trail in brand cost share for a chosen specialty?
- Fields:
state,specialty,brand_share_of_cost,census_region. - Encoding: Sorted lollipops colored by region, with a national weighted-average reference line.
- Interaction: A specialty selector animates re-sorting.
- Implementation: Use keyed joins with transitions.
Coverage Check: Covered vs. Total
- Question: Does the covered-claims subset change the picture?
- Fields:
covered_claims,total_claims,covered_drug_cost_usd,total_drug_cost_usd,specialty. - Encoding: Bars of covered/total ratio for claims and cost by specialty.
- Interaction: Toggle between claims and cost.
- Implementation: Include as a data-quality panel. Ratios near 1 mean the choice of measure matters little.
Cost per Claim: Brand vs. Generic
- Question: How many times more costly is a brand claim than a generic claim?
- Fields: brand cost and brand claims (derived),
generic_drug_cost_usd,generic_claims,specialty. - Encoding: A log-scale bar or dot plot of the brand-to-generic cost-per-claim ratio per specialty.
- Interaction: Annotate the highest-ratio specialties.
- Implementation: Exclude rows with missing generics, and note that costs are gross of rebates.
Linked Dashboard: Region Selector with Specialty Detail
- Question: For a chosen region or state, how does the gap look across all specialties?
- Fields:
census_region,state,specialty, all brand shares,total_claims. - Encoding: A region bar selector on the left controls a dumbbell chart of specialties on the right, plus a mini bubble chart.
- Interaction: Cross-filtering across the linked views, with a reset button.
- Implementation: Keep the selection state in React and pass the filtered data to the D3 render functions.