|
<!DOCTYPE html> |
|
<head> |
|
<meta charset="utf-8"> |
|
<style> |
|
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } |
|
#title {position:absolute;top:12px;left:0px;width:500px;text-align:center;} |
|
svg { width:100%; height: 100% } |
|
svg1 { width:100%; height: 100% } |
|
.axis path, |
|
.axis line { |
|
fill: none; |
|
stroke: #000; |
|
shape-rendering: crispEdges; |
|
} |
|
.div_style1 { |
|
border: 2px solid grey; |
|
width: 1050px; |
|
height: 600px; |
|
} |
|
.div_style2 { |
|
border: 2px solid grey; |
|
width: 1050px; |
|
height: 650px; |
|
|
|
} |
|
.axis path, .axis line { |
|
fill: none; |
|
stroke: black; |
|
shape-rendering: crispEdges; |
|
} |
|
.axis text { |
|
font-family: sans-serif; |
|
font-size: 11px; |
|
} |
|
.dot { |
|
stroke: #000; |
|
} |
|
|
|
</style> |
|
</head> |
|
|
|
<body> |
|
<div id="div1" class="div_style1"> |
|
<ul> |
|
<li><p>Magnitude as position on common scale</p></li> |
|
</ul> |
|
</div> |
|
<div id="div2" class="div_style2"> |
|
<ul> |
|
<li><p>Magnitude as position on common scale</p></li> |
|
<li><p>Identity as color hue</p></li> |
|
<li><p>Magnitude as Area</p></li> |
|
</ul> |
|
</div> |
|
<div id="div3" class="div_style2"> |
|
<ul> |
|
<li><p>Identity as Spatial region</p></li> |
|
<li><p>Identity as color hue</p></li> |
|
<li><p>Magnitude as Area</p></li> |
|
</ul> |
|
</div> |
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> |
|
|
|
<script> |
|
|
|
|
|
|
|
|
|
|
|
var margin = {top: 20, right: 20, bottom: 30, left: 40}, |
|
width = 900 - margin.left - margin.right, |
|
height = 500 - margin.top - margin.bottom; |
|
d3.select(self.frameElement).style("height", "1900px"); |
|
|
|
var x = d3.scale.linear() |
|
.range([0, width]); |
|
|
|
var y = d3.scale.linear() |
|
.range([height, 0]); |
|
|
|
var color = d3.scale.category10(); |
|
|
|
var xAxis = d3.svg.axis() |
|
.scale(x) |
|
.orient("bottom"); |
|
|
|
var yAxis = d3.svg.axis() |
|
.scale(y) |
|
.orient("left"); |
|
|
|
var svg = d3.select("#div1").append("svg") |
|
.attr("width", width + margin.left + margin.right) |
|
.attr("height", height + margin.top + margin.bottom) |
|
.append("g") |
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
|
|
|
d3.tsv("medicarefiltered.tsv", function(error, data) { |
|
if (error) throw error; |
|
|
|
|
|
|
|
data.forEach(function(d) { |
|
d.average_submitted_chrg_amt = +d.average_submitted_chrg_amt; |
|
d.average_Medicare_payment_amt = +d.average_Medicare_payment_amt; |
|
}); |
|
|
|
x.domain(d3.extent(data, function(d) { return d.average_Medicare_payment_amt; })).nice(); |
|
y.domain(d3.extent(data, function(d) { return d.average_submitted_chrg_amt; })).nice(); |
|
|
|
svg.append("g") |
|
.attr("class", "x axis") |
|
.attr("transform", "translate(0," + height + ")") |
|
.call(xAxis) |
|
.append("text") |
|
.attr("class", "label") |
|
.attr("x", width) |
|
.attr("y", -6) |
|
.style("text-anchor", "end") |
|
.text("Average Medicare Payment Amt"); |
|
|
|
svg.append("g") |
|
.attr("class", "y axis") |
|
.call(yAxis) |
|
.append("text") |
|
.attr("class", "label") |
|
.attr("transform", "rotate(-90)") |
|
.attr("y", 6) |
|
.attr("dy", ".71em") |
|
.style("text-anchor", "end") |
|
.text("Average Submitted Charge Amt") |
|
|
|
svg.selectAll(".dot") |
|
.data(data) |
|
.enter().append("circle") |
|
.attr("class", "dot") |
|
.attr("r",5.5) |
|
//.attr("r", function (d) { return d.average_submitted_chrg_amt*0.008; }) |
|
.attr("cx", function(d) { return x(d.average_Medicare_payment_amt); }) |
|
.attr("cy", function(d) { return y(d.average_submitted_chrg_amt); }) |
|
.style("fill", "blue"); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
var svg3 = d3.select("#div2").append("svg") |
|
.attr("width", width + margin.left + margin.right) |
|
.attr("height", height + margin.top + margin.bottom) |
|
.append("g") |
|
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); |
|
|
|
d3.tsv("medicarefiltered.tsv", function(error, data) { |
|
if (error) throw error; |
|
|
|
|
|
|
|
data.forEach(function(d) { |
|
d.average_submitted_chrg_amt = +d.average_submitted_chrg_amt; |
|
d.average_Medicare_payment_amt = +d.average_Medicare_payment_amt; |
|
}); |
|
|
|
x.domain(d3.extent(data, function(d) { return d.average_Medicare_payment_amt; })).nice(); |
|
y.domain(d3.extent(data, function(d) { return d.average_submitted_chrg_amt; })).nice(); |
|
|
|
svg3.append("g") |
|
.attr("class", "x axis") |
|
.attr("transform", "translate(0," + height + ")") |
|
.call(xAxis) |
|
.append("text") |
|
.attr("class", "label") |
|
.attr("x", width) |
|
.attr("y", -6) |
|
.style("text-anchor", "end") |
|
.text("Average Medicare Payment Amt"); |
|
|
|
svg3.append("g") |
|
.attr("class", "y axis") |
|
.call(yAxis) |
|
.append("text") |
|
.attr("class", "label") |
|
.attr("transform", "rotate(-90)") |
|
.attr("y", 6) |
|
.attr("dy", ".71em") |
|
.style("text-anchor", "end") |
|
.text("Average Submitted Charge Amt") |
|
|
|
svg3.selectAll(".dot") |
|
.data(data) |
|
.enter().append("circle") |
|
.attr("class", "dot") |
|
//.attr("r",3.5) |
|
.attr("r", function (d) { return d.average_submitted_chrg_amt*0.008; }) |
|
.attr("cx", function(d) { return x(d.average_Medicare_payment_amt); }) |
|
.attr("cy", function(d) { return y(d.average_submitted_chrg_amt); }) |
|
.style("fill", function(d) { return color(d.nppes_provider_state); }); |
|
|
|
var legend1 = svg3.selectAll(".legend1") |
|
.data(color.domain()) |
|
.enter().append("g") |
|
.attr("class", "legend") |
|
.attr("transform", function(d, i) { return "translate(60," + i * 20 + ")"; }); |
|
|
|
legend1.append("rect") |
|
.attr("x", width - 18) |
|
.attr("width", 18) |
|
.attr("height", 18) |
|
.style("fill", color); |
|
|
|
legend1.append("text") |
|
.attr("x", width - 24) |
|
.attr("y", 9) |
|
.attr("dy", ".25em") |
|
.style("text-anchor", "end") |
|
.text(function(d) { return d; }); |
|
|
|
|
|
}); |
|
|
|
var diameter = 500, //max size of the bubbles |
|
colors = d3.scale.category20(); //color category |
|
|
|
var bubble = d3.layout.pack() |
|
.sort(null) |
|
.size([diameter, diameter]) |
|
.padding(1.5); |
|
|
|
var svg1 = d3.select("#div3") |
|
.append("svg") |
|
.attr("width", diameter) |
|
.attr("height", diameter) |
|
.attr("class", "bubble"); |
|
|
|
d3.tsv("medicareavg.tsv", function(error, data){ |
|
|
|
//convert numerical values from strings to numbers |
|
data = data.map(function(d){ d.value = +d["average_submitted_chrg_amt"]; return d; }); |
|
|
|
//bubbles needs very specific format, convert data to this. |
|
var nodes = bubble.nodes({children:data}).filter(function(d) { return !d.children; }); |
|
|
|
//setup the chart |
|
var bubbles = svg1.append("g") |
|
.attr("transform", "translate(0,0)") |
|
.selectAll(".bubble") |
|
.data(nodes) |
|
.enter(); |
|
|
|
//create the bubbles |
|
bubbles.append("circle") |
|
.attr("r", function(d){ return d.r; }) |
|
.attr("cx", function(d){ return d.x; }) |
|
.attr("cy", function(d){ return d.y; }) |
|
.style("fill", function(d) { return colors(d.nppes_provider_state); }); |
|
|
|
//format the text for each bubble |
|
bubbles.append("text") |
|
.attr("x", function(d){ return d.x; }) |
|
.attr("y", function(d){ return d.y + 5; }) |
|
.attr("text-anchor", "middle") |
|
.text(function(d){ return d["average_submitted_chrg_amt"]; }) |
|
.style({ |
|
"fill":"white", |
|
"font-family":"Helvetica Neue, Helvetica, Arial, san-serif", |
|
"font-size": "12px" |
|
}); |
|
var legend = svg1.selectAll(".legend") |
|
.data(colors.domain()) |
|
.enter().append("g") |
|
.attr("class", "legend") |
|
.attr("transform", function(d, i) { return "translate(60," + i * 20 + ")"; }); |
|
|
|
legend.append("rect") |
|
.attr("x", width - 18) |
|
.attr("width", 18) |
|
.attr("height", 18) |
|
.style("fill", colors); |
|
|
|
legend.append("text") |
|
.attr("x", width - 24) |
|
.attr("y", 9) |
|
.attr("dy", ".25em") |
|
.style("text-anchor", "end") |
|
.text(function(d) { return d; }); |
|
|
|
|
|
}) |
|
|
|
</script> |