Lecture example :)
Last active
December 26, 2016 04:23
-
-
Save pachadotdev/1d5622011fdfc8061a95715bcd7d6b73 to your computer and use it in GitHub Desktop.
Ejemplo de Treemap en D3Plus
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
license: mit |
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
# remember to define your working folder !!! | |
# requiered libraries | |
library(d3plus) | |
# example based on data provided within the package | |
police_killings <- police_killings | |
police_killings$counts <- 1 | |
police_killings <- aggregate(police_killings$counts ~ police_killings$raceethnicity, FUN = sum) | |
colnames(police_killings) <- c("raceethnicity","casualities") | |
police_killings$color <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2") | |
treemap(data = police_killings, variable = "raceethnicity", value = "casualities", | |
title = "Police Killings", subtitle = "Source: FiveThirtyEight", legend = "off") |
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
<!doctype html> | |
<meta charset='utf-8'> | |
<script src="//d3plus.org/js/d3.js"></script> | |
<script src="//d3plus.org/js/d3plus.js"></script> | |
<div id='tree_map'></div> | |
<script> | |
var police_killings = [ | |
{ | |
"raceethnicity": "Asian/Pacific Islander", | |
"casualities": 10, | |
"color": "#999999" | |
}, | |
{ | |
"raceethnicity": "Black", | |
"casualities": 135, | |
"color": "#E69F00" | |
}, | |
{ | |
"raceethnicity": "Hispanic/Latino", | |
"casualities": 67, | |
"color": "#56B4E9" | |
}, | |
{ | |
"raceethnicity": "Native American", | |
"casualities": 4, | |
"color": "#009E73" | |
}, | |
{ | |
"raceethnicity": "Unknown", | |
"casualities": 15, | |
"color": "#F0E442" | |
}, | |
{ | |
"raceethnicity": "White", | |
"casualities": 236, | |
"color": "#0072B2" | |
} | |
] | |
var visualization = d3plus.viz() | |
.container('#tree_map') | |
.data(police_killings) | |
.type('tree_map') | |
.width(1000) | |
.height(600) | |
.resize(true) | |
.id(['raceethnicity']) | |
.size('casualities') | |
.font({'family': 'Lato'}) | |
.labels({'align': 'left', 'valign': 'top'}) | |
.depth(1) | |
.color('color') | |
.title('Police Killings') | |
.title({ | |
'sub': 'Source: FiveThirtyEight' | |
}) | |
.title({ | |
'total': { | |
'font': {'size': 12}, | |
'value': true | |
}, | |
'sub': {'font': {'size': 12}} | |
}) | |
<!-- .legend({'order': {'sort': 'desc', 'value': 'size'}}) --> | |
.legend(false) | |
.icon({'style': 'knockout', 'value': 'image'}) | |
.draw() | |
</script> | |
<link href='https://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment