Last active
February 17, 2018 07:46
-
-
Save jo6gauri/594ebf82b74eb639426ceab1d9f7d0a2 to your computer and use it in GitHub Desktop.
Trellis_Plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script> | |
<script src="trellisPlot.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/addons/p5.dom.min.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
population | no_of_infected_people | disease | loc | year | |
---|---|---|---|---|---|
5023823 | 601 | HEPATITIS A | ARIZONA | 1999 | |
5166697 | 399 | HEPATITIS A | ARIZONA | 2000 | |
5304417 | 341 | HEPATITIS A | ARIZONA | 2001 | |
5452108 | 313 | HEPATITIS A | ARIZONA | 2002 | |
5591206 | 237 | HEPATITIS A | ARIZONA | 2003 | |
5759425 | 210 | HEPATITIS A | ARIZONA | 2004 | |
5974834 | 240 | HEPATITIS A | ARIZONA | 2005 | |
6192100 | 69 | HEPATITIS A | ARIZONA | 2006 | |
6362241 | 163 | HEPATITIS A | ARIZONA | 2007 | |
6499377 | 101 | HEPATITIS A | ARIZONA | 2008 | |
6595778 | 72 | HEPATITIS A | ARIZONA | 2009 | |
6676627 | 72 | HEPATITIS A | ARIZONA | 2010 | |
6482505 | 19 | HEPATITIS A | ARIZONA | 2011 | |
5023823 | 1 | MEASLES | ARIZONA | 1999 | |
5304417 | 1 | MEASLES | ARIZONA | 2001 | |
5023823 | 8 | MUMPS | ARIZONA | 1999 | |
5166697 | 6 | MUMPS | ARIZONA | 2000 | |
5304417 | 1 | MUMPS | ARIZONA | 2001 | |
5452108 | 0 | MUMPS | ARIZONA | 2002 | |
5023823 | 86 | PERTUSSIS | ARIZONA | 1999 | |
5166697 | 142 | PERTUSSIS | ARIZONA | 2000 | |
5304417 | 541 | PERTUSSIS | ARIZONA | 2001 | |
5452108 | 631 | PERTUSSIS | ARIZONA | 2002 | |
5591206 | 91 | PERTUSSIS | ARIZONA | 2003 | |
5759425 | 209 | PERTUSSIS | ARIZONA | 2004 | |
5974834 | 950 | PERTUSSIS | ARIZONA | 2005 | |
6192100 | 354 | PERTUSSIS | ARIZONA | 2006 | |
6362241 | 196 | PERTUSSIS | ARIZONA | 2007 | |
6499377 | 105 | PERTUSSIS | ARIZONA | 2008 | |
6595778 | 155 | PERTUSSIS | ARIZONA | 2009 | |
6676627 | 183 | PERTUSSIS | ARIZONA | 2010 | |
6482505 | 266 | PERTUSSIS | ARIZONA | 2011 | |
5023823 | 11 | RUBELLA | ARIZONA | 1999 | |
5166697 | 1 | RUBELLA | ARIZONA | 2000 | |
33499204 | 2349 | HEPATITIS A | CALIFORNIA | 1999 | |
33994571 | 2261 | HEPATITIS A | CALIFORNIA | 2000 | |
34485623 | 1599 | HEPATITIS A | CALIFORNIA | 2001 | |
34876194 | 1364 | HEPATITIS A | CALIFORNIA | 2002 | |
35251107 | 1045 | HEPATITIS A | CALIFORNIA | 2003 | |
35558419 | 788 | HEPATITIS A | CALIFORNIA | 2004 | |
35795255 | 905 | HEPATITIS A | CALIFORNIA | 2005 | |
35979208 | 688 | HEPATITIS A | CALIFORNIA | 2006 | |
36226122 | 312 | HEPATITIS A | CALIFORNIA | 2007 | |
36580371 | 337 | HEPATITIS A | CALIFORNIA | 2008 | |
36961664 | 239 | HEPATITIS A | CALIFORNIA | 2009 | |
37266600 | 201 | HEPATITIS A | CALIFORNIA | 2010 | |
37691912 | 176 | HEPATITIS A | CALIFORNIA | 2011 | |
33499204 | 18 | MEASLES | CALIFORNIA | 1999 | |
33994571 | 15 | MEASLES | CALIFORNIA | 2000 | |
34485623 | 34 | MEASLES | CALIFORNIA | 2001 | |
34876194 | 0 | MEASLES | CALIFORNIA | 2002 | |
33499204 | 54 | MUMPS | CALIFORNIA | 1999 | |
33994571 | 63 | MUMPS | CALIFORNIA | 2000 | |
34485623 | 37 | MUMPS | CALIFORNIA | 2001 | |
34876194 | 66 | MUMPS | CALIFORNIA | 2002 | |
33499204 | 215 | PERTUSSIS | CALIFORNIA | 1999 | |
33994571 | 208 | PERTUSSIS | CALIFORNIA | 2000 | |
34485623 | 440 | PERTUSSIS | CALIFORNIA | 2001 | |
34876194 | 698 | PERTUSSIS | CALIFORNIA | 2002 | |
35251107 | 635 | PERTUSSIS | CALIFORNIA | 2003 | |
35558419 | 498 | PERTUSSIS | CALIFORNIA | 2004 | |
35795255 | 1609 | PERTUSSIS | CALIFORNIA | 2005 | |
35979208 | 831 | PERTUSSIS | CALIFORNIA | 2006 | |
36226122 | 95 | PERTUSSIS | CALIFORNIA | 2007 | |
36580371 | 276 | PERTUSSIS | CALIFORNIA | 2008 | |
36961664 | 415 | PERTUSSIS | CALIFORNIA | 2009 | |
37266600 | 1265 | PERTUSSIS | CALIFORNIA | 2010 | |
37691912 | 1145 | PERTUSSIS | CALIFORNIA | 2011 | |
33499204 | 5 | RUBELLA | CALIFORNIA | 1999 | |
33994571 | 11 | RUBELLA | CALIFORNIA | 2000 | |
34485623 | 0 | RUBELLA | CALIFORNIA | 2001 | |
34876194 | 2 | RUBELLA | CALIFORNIA | 2002 | |
18882725 | 397 | HEPATITIS A | NEW YORK | 1999 | |
18998044 | 487 | HEPATITIS A | NEW YORK | 2000 | |
19088978 | 411 | HEPATITIS A | NEW YORK | 2001 | |
19161873 | 715 | HEPATITIS A | NEW YORK | 2002 | |
19231101 | 532 | HEPATITIS A | NEW YORK | 2003 | |
19297933 | 380 | HEPATITIS A | NEW YORK | 2004 | |
19330891 | 388 | HEPATITIS A | NEW YORK | 2005 | |
19356564 | 280 | HEPATITIS A | NEW YORK | 2006 | |
19422777 | 262 | HEPATITIS A | NEW YORK | 2007 | |
19467789 | 148 | HEPATITIS A | NEW YORK | 2008 | |
19541453 | 101 | HEPATITIS A | NEW YORK | 2009 | |
19577730 | 2815 | HEPATITIS A | NEW YORK | 2010 | |
19465197 | 112 | HEPATITIS A | NEW YORK | 2011 | |
18998044 | 2 | MEASLES | NEW YORK | 2000 | |
19088978 | 0 | MEASLES | NEW YORK | 2001 | |
19161873 | 1 | MEASLES | NEW YORK | 2002 | |
18882725 | 12 | MUMPS | NEW YORK | 1999 | |
18998044 | 8 | MUMPS | NEW YORK | 2000 | |
19088978 | 13 | MUMPS | NEW YORK | 2001 | |
19161873 | 8 | MUMPS | NEW YORK | 2002 | |
18882725 | 546 | PERTUSSIS | NEW YORK | 1999 | |
18998044 | 212 | PERTUSSIS | NEW YORK | 2000 | |
19088978 | 118 | PERTUSSIS | NEW YORK | 2001 | |
19161873 | 375 | PERTUSSIS | NEW YORK | 2002 | |
19297933 | 1319 | PERTUSSIS | NEW YORK | 2004 | |
19330891 | 558 | PERTUSSIS | NEW YORK | 2005 | |
19356564 | 2007 | PERTUSSIS | NEW YORK | 2006 | |
19422777 | 1109 | PERTUSSIS | NEW YORK | 2007 | |
19467789 | 416 | PERTUSSIS | NEW YORK | 2008 | |
19541453 | 283 | PERTUSSIS | NEW YORK | 2009 | |
19577730 | 808 | PERTUSSIS | NEW YORK | 2010 | |
19465197 | 910 | PERTUSSIS | NEW YORK | 2011 | |
18998044 | 1 | RUBELLA | NEW YORK | 2000 | |
19088978 | 1 | RUBELLA | NEW YORK | 2001 | |
5842564 | 331 | HEPATITIS A | WASHINGTON | 1999 | |
5911122 | 234 | HEPATITIS A | WASHINGTON | 2000 | |
5987785 | 118 | HEPATITIS A | WASHINGTON | 2001 | |
6056187 | 142 | HEPATITIS A | WASHINGTON | 2002 | |
6113262 | 56 | HEPATITIS A | WASHINGTON | 2003 | |
6184289 | 53 | HEPATITIS A | WASHINGTON | 2004 | |
6261282 | 52 | HEPATITIS A | WASHINGTON | 2005 | |
6372243 | 53 | HEPATITIS A | WASHINGTON | 2006 | |
6464979 | 56 | HEPATITIS A | WASHINGTON | 2007 | |
6566073 | 43 | HEPATITIS A | WASHINGTON | 2008 | |
6664195 | 42 | HEPATITIS A | WASHINGTON | 2009 | |
6746199 | 20 | HEPATITIS A | WASHINGTON | 2010 | |
6830038 | 28 | HEPATITIS A | WASHINGTON | 2011 | |
5911122 | 0 | MEASLES | WASHINGTON | 2000 | |
5987785 | 0 | MEASLES | WASHINGTON | 2001 | |
5842564 | 2 | MUMPS | WASHINGTON | 1999 | |
5911122 | 11 | MUMPS | WASHINGTON | 2000 | |
5987785 | 1 | MUMPS | WASHINGTON | 2001 | |
5842564 | 644 | PERTUSSIS | WASHINGTON | 1999 | |
5911122 | 410 | PERTUSSIS | WASHINGTON | 2000 | |
5987785 | 171 | PERTUSSIS | WASHINGTON | 2001 | |
6056187 | 439 | PERTUSSIS | WASHINGTON | 2002 | |
6113262 | 657 | PERTUSSIS | WASHINGTON | 2003 | |
6184289 | 724 | PERTUSSIS | WASHINGTON | 2004 | |
6261282 | 819 | PERTUSSIS | WASHINGTON | 2005 | |
6372243 | 325 | PERTUSSIS | WASHINGTON | 2006 | |
6464979 | 299 | PERTUSSIS | WASHINGTON | 2007 | |
6566073 | 445 | PERTUSSIS | WASHINGTON | 2008 | |
6664195 | 315 | PERTUSSIS | WASHINGTON | 2009 | |
6746199 | 561 | PERTUSSIS | WASHINGTON | 2010 | |
6830038 | 731 | PERTUSSIS | WASHINGTON | 2011 | |
5911122 | 0 | RUBELLA | WASHINGTON | 2000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Width = 1200; | |
var Height = 800; | |
var Padding = 50; | |
var tickSize = 10; | |
var xField = ""; | |
var yField = ""; | |
var disease = ""; | |
var state = ""; | |
var values = []; | |
var x1, y1, x2, y2, rectWidth, rectHeight; | |
var maxX, minX, xArr, minY, maxY, yArr, diseaseArr, stateArr, unique; | |
var fontBold; | |
function preload(){ | |
table=loadTable("StatewiseDiseasePopulationInfo.csv", "csv"); | |
//fontBold = loadFont('assets/Bold.ttf'); | |
} | |
function setup() { | |
createCanvas(Width, Height); | |
xField = table.getColumn(0)[0]; | |
yField = table.getColumn(1)[0]; | |
disease = table.getColumn(2)[0]; | |
stateArr = table.getColumn(3); | |
unique = stateArr.filter(function(item, i, ar){ return ar.indexOf(item) === i; }); | |
// print("Unique Values " + unique); | |
} | |
function sliceData(start, end) { | |
for (var i = 0; i < 2; i++) { | |
var column = table.getColumn(i).slice(start, end); | |
column = column.map(function (num) { | |
return parseFloat(num); | |
}); | |
values.push(column); | |
} | |
} | |
function draw() { | |
background(255, 255, 255); | |
x1 = 200; | |
y1 = 350; | |
x2 = 550; | |
y2 = 350; | |
rectWidth = 350; | |
rectHeight = 300; | |
drawAxes(x1, y1, x2, y2); | |
fill("none"); | |
rect(x1, y1 - 300, rectWidth, rectHeight); | |
drawAxes(x1, y1 + 300, x2, y2 + 300); | |
fill("none"); | |
rect(x1, y1, rectWidth, rectHeight); | |
drawAxes(x1 + 350, y1, x2 + 300, y2); | |
fill("none"); | |
rect(x1 + 350, y1 - 300, rectWidth, rectHeight); | |
drawAxes(x1 + 350, y1 + 300, x2 + 300, y2 + 300); | |
fill("none"); | |
rect(x1 + 350, y1, rectWidth, rectHeight); | |
sliceData(1, 35); | |
xArr = values[0]; | |
yArr = values[1]; | |
diseaseArr = table.getColumn(2).slice(1, 35); | |
maxX = Math.max.apply(Math, xArr); | |
maxY = Math.max.apply(Math, yArr); | |
minX = Math.min.apply(Math, xArr); | |
minY = Math.min.apply(Math, yArr); | |
drawPlot(x1, 350, x2, 650); | |
textSize(20); | |
fill(0, 0, 255); | |
stroke(0); | |
text("ARIZONA", x1 + 90, 500); | |
values = []; | |
sliceData(36, 73); | |
xArr = values[0]; | |
yArr = values[1]; | |
diseaseArr = table.getColumn(2).slice(36, 73); | |
maxX = Math.max.apply(Math, xArr); | |
maxY = Math.max.apply(Math, yArr); | |
minX = Math.min.apply(Math, xArr); | |
minY = Math.min.apply(Math, yArr); | |
drawPlot(x1, 50, x2, 350); | |
textSize(20); | |
fill(0, 0, 255); | |
stroke(0); | |
text("CALIFORNIA", x1 + 90, 250); | |
values = []; | |
sliceData(74, 107); | |
xArr = values[0]; | |
yArr = values[1]; | |
diseaseArr = table.getColumn(2).slice(74, 107); | |
maxX = Math.max.apply(Math, xArr); | |
maxY = Math.max.apply(Math, yArr); | |
minX = Math.min.apply(Math, xArr); | |
minY = Math.min.apply(Math, yArr); | |
drawPlot(x1 + 350, 350, x2 + 300, 650); | |
textSize(20); | |
fill(0, 0, 255); | |
stroke(0); | |
text("NEW YORK", x1 + 400, 500); | |
values = []; | |
sliceData(108, 139); | |
xArr = values[0]; | |
yArr = values[1]; | |
diseaseArr = table.getColumn(2).slice(108, 139); | |
maxX = Math.max.apply(Math, xArr); | |
maxY = Math.max.apply(Math, yArr); | |
minX = Math.min.apply(Math, xArr); | |
minY = Math.min.apply(Math, yArr); | |
drawPlot(x1 + 350, 50, x2 + 300, 350); | |
textSize(20); | |
fill(0, 0, 255); | |
stroke(0); | |
text("WASHINGTON", x1 + 400, 250); | |
values = []; | |
textSize(25); | |
fill(0, 0, 0) | |
text("Population Vs. Infected people with different diseases differentiated by State", x1, 20); | |
textSize(20); | |
fill(0, 0, 255); | |
text(xField, x2 + 300, y2 + 350); | |
text(yField, x1 - 180, y2 - 310); | |
} | |
function drawPlot(x1, y1, x2, y2) { | |
var tickGap = (x2 - x1) / 5; | |
var XAxisScale = minX, YAxisScale = 0; | |
var temp = (maxX - minX) / 5; | |
textSize(15); | |
fill(0, 0, 0); | |
//print("Max and Min and Temp is " + maxX + " " + minX + " " + temp); | |
for (var i = 1; i <= 5; i++) { | |
if (i == 5) | |
XAxisScale = maxX; | |
text(int(XAxisScale), x1 + i * tickGap - 30, y2 + 30); | |
XAxisScale += temp; | |
} | |
tickGap = (y2 - y1) / 5; | |
YAxisScale = 0; | |
// print("Start at " + YAxisScale); | |
for (i = 0; i <= 5; i++) { | |
text(YAxisScale, x1 - 45, y2 - i * tickGap + 4); | |
YAxisScale += int(maxY / 5); | |
} | |
var selectedPoints = []; | |
for (i = 0; i < xArr.length; i++) { | |
selectedPoints.push(createVector(xArr[i], yArr[i])); | |
} | |
for (i = 0; i < selectedPoints.length; i++) { | |
var point = selectedPoints[i]; | |
var newx1 = x1; | |
var newx2 = x2; | |
// print("MAx values are : " + maxX + "3899518, " 150537+ maxY); | |
var xPos = int(map(point.x, (minX - temp) - (temp / 4), maxX, newx1, newx2)); | |
var newy1 = y2; | |
var newy2 = y1; | |
var yPos = int(map(point.y, 0, maxY, newy1, newy2)); | |
// print("xpos an dypos are " + xPos + " " + yPos); | |
colorbyDisease(diseaseArr[i + 1], xPos, yPos); | |
} | |
for (i = 0; i < selectedPoints.length; i++) { | |
var point = selectedPoints[i]; | |
var newx1 = x1; | |
var newx2 = x2; | |
var xPos = map(point.x, (minX - temp) - (temp / 4), maxX, newx1, newx2); | |
var newy1 = y2; | |
var newy2 = y1; | |
var yPos = int(map(point.y, 0, maxY, newy1, newy2)); | |
if (sq(mouseX - xPos) + sq(mouseY - yPos) < 80) { | |
print("hi"); | |
fill(230, 138, 0); | |
ellipse(xPos, yPos, 10, 10); | |
// print(point); | |
text(diseaseArr[i + 1] + " (" + point.x + ", " + point.y + ")", mouseX + 15, mouseY); | |
} | |
} | |
} | |
function drawAxes(x1, y1, x2, y2) { | |
stroke(100, 100, 100); | |
strokeWeight(1.5); | |
fill(100, 100, 100); | |
textSize(18); | |
line(x1, y1, x2, y2); | |
var tickGap = (x2 - x1) / 5; | |
for (var j = 0; j < 5; j++) { | |
line(x1 + (j + 1) * tickGap, y1, x1 + (j + 1) * tickGap, y1 + tickSize); | |
} | |
// text(xField, x2 + 5, y2 + 40); | |
x1 = x1; | |
x2 = x1; | |
y1 = y1; | |
y2 = y1 - 300; | |
line(x1, y1, x2, y2); | |
tickGap = (y1 - y2) / 5; | |
for (var j = 0; j < 5; j++) { | |
line(x1, y2 + j * tickGap, x1 - tickSize, y2 + j * tickGap); | |
} | |
// text(yField, x1, y2 - 15); | |
} | |
function colorbyDisease(diseaseName, xPos, yPos) { | |
switch (diseaseName) { | |
case 'HEPATITIS A': | |
fill(0, 204, 0); | |
ellipse(xPos, yPos, 10, 10); | |
rect(Width / 2 + 350, Padding / 2 + 100, Width / 24, Padding / 10); | |
fill(0, 0, 0); | |
textSize(18); | |
text("HEPATITIS A", Width / 2 + 400, Padding / 2 + 115); | |
break; | |
case 'PERTUSSIS': | |
fill(255, 0, 102); | |
ellipse(xPos, yPos, 10, 10); | |
rect(Width / 2 + 350, Padding / 2 + 125, Width / 24, Padding / 10); | |
fill(0, 0, 0); | |
textSize(18); | |
text("PERTUSSIS", Width / 2 + 400, Padding / 2 + 140); | |
break; | |
default: | |
fill(0, 51, 204); | |
ellipse(xPos, yPos, 10, 10); | |
rect(Width / 2 + 350, Padding / 2 + 150, Width / 24, Padding / 10); | |
fill(0, 0, 0); | |
textSize(18); | |
text("OTHER", Width / 2 + 400, Padding / 2 + 165); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment