Last active
December 20, 2015 07:49
-
-
Save walkerke/6095695 to your computer and use it in GitHub Desktop.
DFW-area projections with rCharts and Highcharts
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
##Script to build a Highcharts line chart with rCharts## | |
require(rCharts) | |
txproj <- read.csv("https://dl.dropbox.com/s/9abhe4zbojhcysm/2012allcntymigtot.csv") | |
metrotx <- subset(txproj, migration_scenario == "0.5 Scen" & (county_name == "Collin County" | | |
county_name == "Dallas County" | county_name == "Denton County" | | |
county_name = "Tarrant County"), | |
select = c(year, county_name, total, migration_scenario)) | |
h1 <- hPlot(x = "year", y = "total", data = metrotx, type = "line", group = "county_name", | |
title = "Projected population, DFW-area counties", | |
subtitle = "Data source: Texas State Demographer, 0.5 migration scenario") | |
h1$yAxis(title = list(text = "Projected population")) | |
h1$xAxis(title = list(text = "Year")) | |
h1$xAxis(labels = list(formatter = "#! function() { return this.value; } !#")) | |
h1 |
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'> | |
<html> | |
<head> | |
<link rel='stylesheet' href="http://netdna.bootstrapcdn.com/bootswatch/2.3.1/cosmo/bootstrap.min.css"> | |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" > | |
<link rel='stylesheet' href="http://twitter.github.io/bootstrap/2.3.2/assets/js/google-code-prettify/prettify.css"> | |
<script src='http://code.jquery.com/jquery-1.9.1.min.js' type='text/javascript'></script> | |
<script src='http://code.highcharts.com/highcharts.js' type='text/javascript'></script> | |
<script src='http://code.highcharts.com/highcharts-more.js' type='text/javascript'></script> | |
<style> | |
.rChart { | |
display: block; | |
margin-left: auto; | |
margin-right: auto; | |
width: 800px; | |
height: 400px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='chart1d8c43796404' class='rChart highcharts'></div> | |
<script type='text/javascript'> | |
(function($){ | |
$(function () { | |
var chart = new Highcharts.Chart({ | |
"dom": "chart1d8c43796404", | |
"width": 800, | |
"height": 400, | |
"credits": { | |
"href": null, | |
"text": null | |
}, | |
"title": { | |
"text": "Projected population, DFW-area counties" | |
}, | |
"yAxis": { | |
"title": { | |
"text": "Projected population" | |
} | |
}, | |
"series": [ | |
{ | |
"data": [ | |
[ | |
2010, | |
782341 | |
], | |
[ | |
2011, | |
801206 | |
], | |
[ | |
2012, | |
820401 | |
], | |
[ | |
2013, | |
839959 | |
], | |
[ | |
2014, | |
859294 | |
], | |
[ | |
2015, | |
879105 | |
], | |
[ | |
2016, | |
898895 | |
], | |
[ | |
2017, | |
918815 | |
], | |
[ | |
2018, | |
939242 | |
], | |
[ | |
2019, | |
959776 | |
], | |
[ | |
2020, | |
980666 | |
], | |
[ | |
2021, | |
1002279 | |
], | |
[ | |
2022, | |
1024386 | |
], | |
[ | |
2023, | |
1047026 | |
], | |
[ | |
2024, | |
1070385 | |
], | |
[ | |
2025, | |
1094333 | |
], | |
[ | |
2026, | |
1119045 | |
], | |
[ | |
2027, | |
1144567 | |
], | |
[ | |
2028, | |
1170575 | |
], | |
[ | |
2029, | |
1197510 | |
], | |
[ | |
2030, | |
1224988 | |
], | |
[ | |
2031, | |
1252882 | |
], | |
[ | |
2032, | |
1281535 | |
], | |
[ | |
2033, | |
1310498 | |
], | |
[ | |
2034, | |
1339891 | |
], | |
[ | |
2035, | |
1369604 | |
], | |
[ | |
2036, | |
1399860 | |
], | |
[ | |
2037, | |
1430315 | |
], | |
[ | |
2038, | |
1460856 | |
], | |
[ | |
2039, | |
1491735 | |
], | |
[ | |
2040, | |
1522618 | |
], | |
[ | |
2041, | |
1553910 | |
], | |
[ | |
2042, | |
1585155 | |
], | |
[ | |
2043, | |
1616487 | |
], | |
[ | |
2044, | |
1647902 | |
], | |
[ | |
2045, | |
1679409 | |
], | |
[ | |
2046, | |
1711255 | |
], | |
[ | |
2047, | |
1743187 | |
], | |
[ | |
2048, | |
1775245 | |
], | |
[ | |
2049, | |
1807681 | |
], | |
[ | |
2050, | |
1840860 | |
] | |
], | |
"name": "Collin County", | |
"type": "line", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
2010, | |
2368139 | |
], | |
[ | |
2011, | |
2394925 | |
], | |
[ | |
2012, | |
2421987 | |
], | |
[ | |
2013, | |
2448796 | |
], | |
[ | |
2014, | |
2476247 | |
], | |
[ | |
2015, | |
2503717 | |
], | |
[ | |
2016, | |
2530186 | |
], | |
[ | |
2017, | |
2557348 | |
], | |
[ | |
2018, | |
2584304 | |
], | |
[ | |
2019, | |
2610734 | |
], | |
[ | |
2020, | |
2637053 | |
], | |
[ | |
2021, | |
2663344 | |
], | |
[ | |
2022, | |
2689599 | |
], | |
[ | |
2023, | |
2715329 | |
], | |
[ | |
2024, | |
2741149 | |
], | |
[ | |
2025, | |
2766677 | |
], | |
[ | |
2026, | |
2792262 | |
], | |
[ | |
2027, | |
2817175 | |
], | |
[ | |
2028, | |
2842332 | |
], | |
[ | |
2029, | |
2867401 | |
], | |
[ | |
2030, | |
2892297 | |
], | |
[ | |
2031, | |
2917842 | |
], | |
[ | |
2032, | |
2942884 | |
], | |
[ | |
2033, | |
2968467 | |
], | |
[ | |
2034, | |
2994210 | |
], | |
[ | |
2035, | |
3020031 | |
], | |
[ | |
2036, | |
3046697 | |
], | |
[ | |
2037, | |
3073169 | |
], | |
[ | |
2038, | |
3099728 | |
], | |
[ | |
2039, | |
3126948 | |
], | |
[ | |
2040, | |
3154331 | |
], | |
[ | |
2041, | |
3181940 | |
], | |
[ | |
2042, | |
3209361 | |
], | |
[ | |
2043, | |
3237085 | |
], | |
[ | |
2044, | |
3265383 | |
], | |
[ | |
2045, | |
3294172 | |
], | |
[ | |
2046, | |
3322587 | |
], | |
[ | |
2047, | |
3351052 | |
], | |
[ | |
2048, | |
3380030 | |
], | |
[ | |
2049, | |
3409585 | |
], | |
[ | |
2050, | |
3438782 | |
] | |
], | |
"name": "Dallas County", | |
"type": "line", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
2010, | |
662614 | |
], | |
[ | |
2011, | |
677902 | |
], | |
[ | |
2012, | |
693878 | |
], | |
[ | |
2013, | |
709861 | |
], | |
[ | |
2014, | |
725887 | |
], | |
[ | |
2015, | |
742002 | |
], | |
[ | |
2016, | |
758571 | |
], | |
[ | |
2017, | |
775319 | |
], | |
[ | |
2018, | |
792476 | |
], | |
[ | |
2019, | |
810030 | |
], | |
[ | |
2020, | |
827987 | |
], | |
[ | |
2021, | |
845888 | |
], | |
[ | |
2022, | |
864112 | |
], | |
[ | |
2023, | |
882831 | |
], | |
[ | |
2024, | |
902052 | |
], | |
[ | |
2025, | |
922015 | |
], | |
[ | |
2026, | |
942254 | |
], | |
[ | |
2027, | |
963227 | |
], | |
[ | |
2028, | |
984520 | |
], | |
[ | |
2029, | |
1006381 | |
], | |
[ | |
2030, | |
1028537 | |
], | |
[ | |
2031, | |
1051161 | |
], | |
[ | |
2032, | |
1074058 | |
], | |
[ | |
2033, | |
1097349 | |
], | |
[ | |
2034, | |
1120866 | |
], | |
[ | |
2035, | |
1144763 | |
], | |
[ | |
2036, | |
1168960 | |
], | |
[ | |
2037, | |
1193353 | |
], | |
[ | |
2038, | |
1218046 | |
], | |
[ | |
2039, | |
1243045 | |
], | |
[ | |
2040, | |
1268195 | |
], | |
[ | |
2041, | |
1293774 | |
], | |
[ | |
2042, | |
1319526 | |
], | |
[ | |
2043, | |
1345397 | |
], | |
[ | |
2044, | |
1371528 | |
], | |
[ | |
2045, | |
1398015 | |
], | |
[ | |
2046, | |
1424784 | |
], | |
[ | |
2047, | |
1451904 | |
], | |
[ | |
2048, | |
1479592 | |
], | |
[ | |
2049, | |
1507615 | |
], | |
[ | |
2050, | |
1535959 | |
] | |
], | |
"name": "Denton County", | |
"type": "line", | |
"marker": { | |
"radius": 3 | |
} | |
}, | |
{ | |
"data": [ | |
[ | |
2010, | |
1809034 | |
], | |
[ | |
2011, | |
1832223 | |
], | |
[ | |
2012, | |
1855462 | |
], | |
[ | |
2013, | |
1879128 | |
], | |
[ | |
2014, | |
1902589 | |
], | |
[ | |
2015, | |
1926170 | |
], | |
[ | |
2016, | |
1949650 | |
], | |
[ | |
2017, | |
1973623 | |
], | |
[ | |
2018, | |
1997427 | |
], | |
[ | |
2019, | |
2021783 | |
], | |
[ | |
2020, | |
2046408 | |
], | |
[ | |
2021, | |
2070682 | |
], | |
[ | |
2022, | |
2095522 | |
], | |
[ | |
2023, | |
2120801 | |
], | |
[ | |
2024, | |
2145616 | |
], | |
[ | |
2025, | |
2171227 | |
], | |
[ | |
2026, | |
2196830 | |
], | |
[ | |
2027, | |
2223097 | |
], | |
[ | |
2028, | |
2248931 | |
], | |
[ | |
2029, | |
2275085 | |
], | |
[ | |
2030, | |
2300798 | |
], | |
[ | |
2031, | |
2326875 | |
], | |
[ | |
2032, | |
2352327 | |
], | |
[ | |
2033, | |
2378008 | |
], | |
[ | |
2034, | |
2403304 | |
], | |
[ | |
2035, | |
2428789 | |
], | |
[ | |
2036, | |
2453689 | |
], | |
[ | |
2037, | |
2478587 | |
], | |
[ | |
2038, | |
2503222 | |
], | |
[ | |
2039, | |
2528224 | |
], | |
[ | |
2040, | |
2552459 | |
], | |
[ | |
2041, | |
2577069 | |
], | |
[ | |
2042, | |
2601445 | |
], | |
[ | |
2043, | |
2625591 | |
], | |
[ | |
2044, | |
2649523 | |
], | |
[ | |
2045, | |
2673887 | |
], | |
[ | |
2046, | |
2698308 | |
], | |
[ | |
2047, | |
2722708 | |
], | |
[ | |
2048, | |
2747433 | |
], | |
[ | |
2049, | |
2772140 | |
], | |
[ | |
2050, | |
2797199 | |
] | |
], | |
"name": "Tarrant County", | |
"type": "line", | |
"marker": { | |
"radius": 3 | |
} | |
} | |
], | |
"xAxis": { | |
"labels": { | |
"formatter": function() { return this.value; } | |
} | |
}, | |
"subtitle": { | |
"text": "Data source: Texas State Demographer, 0.5 migration scenario" | |
}, | |
"id": "chart1d8c43796404", | |
"chart": { | |
"renderTo": "chart1d8c43796404" | |
} | |
}); | |
}); | |
})(jQuery); | |
</script> | |
</body> | |
<!-- Google Prettify --> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/prettify/188.0.0/prettify.js"></script> | |
<script | |
src='https://google-code-prettify.googlecode.com/svn-history/r232/trunk/src/lang-r.js'> | |
</script> | |
<script> | |
var pres = document.getElementsByTagName("pre"); | |
for (var i=0; i < pres.length; ++i) { | |
pres[i].className = "prettyprint linenums"; | |
} | |
prettyPrint(); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment