Skip to content

Instantly share code, notes, and snippets.

@will-s-t
Created November 1, 2015 22:01
Show Gist options
  • Save will-s-t/0239dd3253edaf7c6b54 to your computer and use it in GitHub Desktop.
Save will-s-t/0239dd3253edaf7c6b54 to your computer and use it in GitHub Desktop.
wstBacteriaScatter
type commonName latinName logGram logHour Mb MbGroup MbNumericalGroup
Bacteria Haemophilus influenza Haemophilus influenza -13.0 -0.2 1.8 1–10 1
Bacteria Pelagibacter ubique Pelagibacter ubique -14.0 -1.7 1.3 1–10 1
Bacteria Prochlorococcus marinus Prochlorococcus marinus -13.0 -1.8 2.7 1–10 1
Bacteria E. coli Escherichia coli -12.0 -0.4 4.6 1–10 1
Bacteria Mycobacterium tuberculosis Mycobacterium tuberculosis -12.6 -1.4 4.4 1–10 1
Bacteria Myxococcus xanthus Myxococcus xanthus -11.0 0.6 9.1 1–10 1
Archaea Sulfolobus islandicus Sulfolobus islandicus -12.3 1.6 2.9 1–10 1
Eukaryota bakers' yeast Saccharomyces cerevisiae -9.2 0.3 12 11–100 2
Eukaryota Chlamydomonas Chlamydomonas reinhardtii -9.3 1.0 120 101–1000 3
Eukaryota slime mold Dictyostelium discoideum -4.6 0.6 34 11–100 2
Eukaryota Paramecium Paramecium tetraurelia -7.0 -0.3 72 11–100 2
Insects nematode Caenorhabditis elegans -5.5 2.0 103 101–1000 3
Insects fruit fly Drosophila melanogaster -3.3 2.4 165 101–1000 3
Insects mosquito Anopheles gambiae -2.8 2.6 278 101–1000 3
Insects honey bee Apis mellifera -1.1 3.9 236 101–1000 3
Insects flour beetle Triboleum castaneum -2.7 2.9 204 101–1000 3
Vertebrates marbled lungfish Protopterus aethiopicus 4.2 4.5 130000 10000+ 5
Vertebrates zebrafish Danio rerio -0.0 3.3 1412 1001–10000 4
Vertebrates Western clawed frog Xenopus tropicalis 0.7 3.6 1438 1001–10000 4
Vertebrates mouse Mus musculus 1.5 2.4 2700 1001–10000 4
Vertebrates chicken Gallus gallus 3.0 3.8 1047 1001–10000 4
Vertebrates human Homo sapiens 4.8 5.3 3200 1001–10000 4
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>The amazing properties of bacteria</title>
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style type="text/css">
body {
margin: 0;
background-color: lightGray;
font-family: Georgia, Times, serif;
}
#container {
width: 800px;
margin-left: auto;
margin-right: auto;
background-color: #FFF;
margin-top: 50px;
box-shadow: 3px 3px 5px 6px #bbb;
}
h2 {
text-align: center;
font-size: 20px;
font-weight: bold;
padding-top: 15px;
}
}
</style>
</head>
<body>
<div id="container">
<h2>The amazing properties of bacteria</h2>
<section id="chart"></section>
</div>
<script type="text/javascript">
var w = 800;
var h = 600;
var padding = [50, 50, 50, 50];
var widthScale = d3.scale.linear()
.range([ padding[3], w - padding[1] - padding[3] ]);
var heightScale = d3.scale.linear()
.range([ h - padding[2] - padding[0], padding[0] ]);
var svg = d3.select("#chart")
.append("svg")
.attr("width", w)
.attr("height", h);
d3.csv("bacteria.csv", function(data) {
widthScale.domain([
d3.min(data, function(d) {
return +d.logHour;
})
,
d3.max(data, function(d) {
return +d.logHour;
}) ]);
heightScale.domain([ d3.min(data, function(d) {
return +d.logGram;
})
,
d3.max(data, function(d) {
return +d.logGram;
}) ]);
var groups = svg.selectAll ("g")
.data(data)
.enter()
.append("g")
.attr("class", "point");
var points = groups.append("circle")
.attr("cx", function(d) {
return widthScale(d.logHour);
})
.attr("cy", function(d) {
return heightScale(d.logGram);
})
.attr("r", 0)
.attr("fill", function(d) {
// console.log(d.type);
if(d.type == "Bacteria") {
return "#B34B79" ;
} else if(d.type == "Archaea") {
return "#C37D15" ;
} else if(d.type == "Eukaryota") {
return "#A9BF31" ;
} else if(d.type == "Insects") {
return "#5F331A" ;
} else if(d.type == "Vertebrates") {
return "#41A9B1" ;
} else {
return "#F00" ;
}
})
points.transition()
.delay(function(d, i) {
return i * 30;
})
.duration(1000)
.attr("r", function(d) {
return +d.MbNumericalGroup * 3 + 2 ;
});
// findRingsNo = function(d) {
// if(d.type == "Archaea") {
// return 1;
// } else if(d.type == "Eukaryota") {
// return 2;
// } else if(d.type == "Insects") {
// return 3;
// } else if(d.type == "Vertebrates") {
// return 4;
// } else {
// return 0;
// }}
// var ringsNo = findRingsNo(d);
// console.log(ringsNo);
var rings = groups.append("circle")
.attr("cx", function(d) {
return widthScale(d.logHour);
})
.attr("cy", function(d) {
return heightScale(d.logGram);
})
.attr("r", 6)
.attr("stroke", "#FFF")
.attr("opacity", function(d) {
if(d.MbNumericalGroup < 2) {
return(0);
} else {
return(1);
}
})
.attr("fill", "none");
var rings = groups.append("circle")
.attr("cx", function(d) {
return widthScale(d.logHour);
})
.attr("cy", function(d) {
return heightScale(d.logGram);
})
.attr("r", 9)
.attr("stroke", "#FFF")
.attr("opacity", function(d) {
if(d.MbNumericalGroup < 3) {
return(0);
} else {
return(1);
}
})
.attr("fill", "none");
var rings = groups.append("circle")
.attr("cx", function(d) {
return widthScale(d.logHour);
})
.attr("cy", function(d) {
return heightScale(d.logGram);
})
.attr("r", 12)
.attr("stroke", "#FFF")
.attr("opacity", function(d) {
if(d.MbNumericalGroup < 4) {
return(0);
} else {
return(1);
}
})
.attr("fill", "none");
var rings = groups.append("circle")
.attr("cx", function(d) {
return widthScale(d.logHour);
})
.attr("cy", function(d) {
return heightScale(d.logGram);
})
.attr("r", 15)
.attr("stroke", "#FFF")
.attr("opacity", function(d) {
if(d.MbNumericalGroup < 5) {
return(0);
} else {
return(1);
}
})
.attr("fill", "none");
// svg.append("g");
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment