Skip to content

Instantly share code, notes, and snippets.

@AmritPatel
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmritPatel/123996510e44a6e75778 to your computer and use it in GitHub Desktop.
Save AmritPatel/123996510e44a6e75778 to your computer and use it in GitHub Desktop.
Map of Baltimore Nursing Homes
# View @ http://rcharts.github.io/viewer/?123996510e44a6e75778
library(dplyr)
library(rCharts)
library(RDSTK)
# Read in the data
x <- getURL("https://gist.githubusercontent.com/AmritPatel/7fffd1f645df4f74aae9/raw/f2b109ed22d10e2e36e6afc3f45e6efea93b85d5/balt_nursing_homes.csv")
nursing_homes <- read.csv(text = x)
# Use dataframe wrapper
nursing_homes_df <- tbl_df(nursing_homes)
nursing_homes_df$pos <- do.call(paste, c(nursing_homes_df[c("Address", "City", "State")], sep = " "))
# initialize plot
map <- Leaflet$new()
# set the initial view
map$setView(c(39.33351, -76.64981), zoom = 13)
# iterate over the data
for(i in 1:nrow(nursing_homes_df)) {
# format the beginning of the name string for the tooltip
name <- gsub("^", "<p>", nursing_homes_df[i, "Provider.Name"])
# format the end of the name string for the tooltip
name <- gsub("$", "<p>", name)
# remove the newlines from the location string to pass to s2c function
loc <- gsub("\n", " ", nursing_homes_df[i, "pos"])
# run the s2c function to obtain lat, long for adding tooltip
test <- street2coordinates(loc)
# add tooltip given lat, long and use the name of the nursing home for the desc
map$marker(c(test$latitude, test$longitude), bindPopup = name)
}
# show the map
map
<!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://getbootstrap.com/2.3.2/assets/js/google-code-prettify/prettify.css">
<link rel='stylesheet' href="http://aozora.github.io/bootplus/assets/css/docs.css">
<link rel='stylesheet' href='http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css'>
<script src='http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js' type='text/javascript'></script>
<script src='https://rawgithub.com/leaflet-extras/leaflet-providers/gh-pages/leaflet-providers.js' type='text/javascript'></script>
<script src='http://harrywood.co.uk/maps/examples/leaflet/leaflet-plugins/layer/vector/KML.js' type='text/javascript'></script>
<style>
.rChart {
display: block
margin: auto auto;
width: 100%;
height: 400px;
}
/*
body {
margin-top: 60px;
}
*/
</style>
</head>
<body>
<div class='container'>
<div class='row'>
<div class='span8'>
<div class="bs-docs-example">
<div id='chart11a41c2bd172' class='rChart leaflet'>
</div>
<br/>
<pre><code class='r'>library(dplyr)
library(rCharts)
library(RDSTK)
# Read in the data
x &lt;- getURL(&quot;https://gist.githubusercontent.com/AmritPatel/7fffd1f645df4f74aae9/raw/f2b109ed22d10e2e36e6afc3f45e6efea93b85d5/balt_nursing_homes.csv&quot;)
nursing_homes &lt;- read.csv(text = x)
# Use dataframe wrapper
nursing_homes_df &lt;- tbl_df(nursing_homes)
nursing_homes_df$pos &lt;- do.call(paste, c(nursing_homes_df[c(&quot;Address&quot;, &quot;City&quot;, &quot;State&quot;)], sep = &quot; &quot;))
# initialize plot
map &lt;- Leaflet$new()
# set the initial view
map$setView(c(39.33351, -76.64981), zoom = 13)
# iterate over the data
for(i in 1:nrow(nursing_homes_df)) {
# format the beginning of the name string for the tooltip
name &lt;- gsub(&quot;^&quot;, &quot;&lt;p&gt;&quot;, nursing_homes_df[i, &quot;Provider.Name&quot;])
# format the end of the name string for the tooltip
name &lt;- gsub(&quot;$&quot;, &quot;&lt;p&gt;&quot;, name)
# remove the newlines from the location string to pass to s2c function
loc &lt;- gsub(&quot;\n&quot;, &quot; &quot;, nursing_homes_df[i, &quot;pos&quot;])
# run the s2c function to obtain lat, long for adding tooltip
test &lt;- street2coordinates(loc)
# add tooltip given lat, long and use the name of the nursing home for the desc
map$marker(c(test$latitude, test$longitude), bindPopup = name)
}
# show the map
map
</code></pre>
</div>
</div>
</div>
</div>
<script>
var spec = {
"dom": "chart11a41c2bd172",
"width": 700,
"height": 400,
"urlTemplate": "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
"layerOpts": {
"attribution": "Map data<a href=\"http://openstreetmap.org\">OpenStreetMap</a>\n contributors, Imagery<a href=\"http://mapbox.com\">MapBox</a>"
},
"center": [ 39.33351, -76.64981 ],
"zoom": 13,
"id": "chart11a41c2bd172"
}
var map = L.map(spec.dom, spec.mapOpts)
map.setView(spec.center, spec.zoom);
if (spec.provider){
L.tileLayer.provider(spec.provider).addTo(map)
} else {
L.tileLayer(spec.urlTemplate, spec.layerOpts).addTo(map)
}
L
.marker([
39.284,
-76.689
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Irvington <p>")
L
.marker([
39.344,
-76.707
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Lochearn<p>")
L
.marker([
39.289,
-76.506
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Northpoint<p>")
L
.marker([
39.209,
-76.563
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Old Court<p>")
L
.marker([
39.3,
-76.643
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Sandtown<p>")
L
.marker([
39.278,
-76.573
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Canton Harbor<p>")
L
.marker([
39.316,
-76.617
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Charles Village<p>")
L
.marker([
39.363,
-76.552
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Cold Spring<p>")
L
.marker([
39.321,
-76.617
])
.addTo( map )
.bindPopup("<p>Future Care Nursing Home - Homewood<p>")
L
.marker([
39.443,
-76.514
])
.addTo( map )
.bindPopup("<p>Glen Meadows Retirement Community<p>")
L
.marker([
39.358,
-76.584
])
.addTo( map )
.bindPopup("<p>Good Samaritan Nursing Center<p>")
L
.marker([
39.665,
-76.887
])
.addTo( map )
.bindPopup("<p>Longview Nursing Home <p>")
L
.marker([
39.502,
-76.327
])
.addTo( map )
.bindPopup("<p>Lorien Nursing & Rehabilitation Center - Bel Air<p>")
L
.marker([
39.176,
-76.776
])
.addTo( map )
.bindPopup("<p>Lorien Nursing & Rehabilitation Center - Elkridge<p>")
L
.marker([
39.646,
-77.159
])
.addTo( map )
.bindPopup("<p>Lorien Taneytown, Inc. <p>")
L
.marker([
39.412,
-76.613
])
.addTo( map )
.bindPopup("<p>ManorCare Health Services -Dulaney<p>")
L
.marker([
39.346,
-76.641
])
.addTo( map )
.bindPopup("<p>ManorCare Health Services -Roland Park<p>")
L
.marker([
39.262,
-76.692
])
.addTo( map )
.bindPopup("<p>ManorCare Health Services -Rossville<p>")
L
.marker([
39.408,
-76.632
])
.addTo( map )
.bindPopup("<p>ManorCare Health Services - Ruxton<p>")
L
.marker([
39.401,
-76.594
])
.addTo( map )
.bindPopup("<p>ManorCare Health Services - Towson<p>")
L
.marker([
39.306,
-76.754
])
.addTo( map )
.bindPopup("<p>ManorCare Health Services - Woodbrigde Valley<p>")
L
.marker([
39.441,
-76.807
])
.addTo( map )
.bindPopup("<p>Arden Courts of Pikesville<p>")
L
.marker([
39.441,
-76.807
])
.addTo( map )
.bindPopup("<p>Springhouse of Pikesville<p>")
L
.marker([
39.413,
-76.643
])
.addTo( map )
.bindPopup("<p>Arden Courts of Towson<p>")
L
.marker([
39.383,
-76.627
])
.addTo( map )
.bindPopup("<p>Maria Health Care Center, Inc.<p>")
L
.marker([
39.377,
-76.77
])
.addTo( map )
.bindPopup("<p>North Oaks<p>")
L
.marker([
39.378,
-76.817
])
.addTo( map )
.bindPopup("<p>Northwest Hospital Center Subacute Unit<p>")
L
.marker([
39.342,
-76.665
])
.addTo( map )
.bindPopup("<p>Northwest Nursing & Rehabilitation Center<p>")
L
.marker([
39.391,
-76.506
])
.addTo( map )
.bindPopup("<p>Oak Crest Village<p>")
L
.marker([
39.258,
-76.738
])
.addTo( map )
.bindPopup("<p>St. Joseph's Nursing Home<p>")
L
.marker([
39.377,
-76.621
])
.addTo( map )
.bindPopup("<p>The Villa<p>")
L
.marker([
39.385,
-76.577
])
.addTo( map )
.bindPopup("<p>Transitional Care At Good Samaritan <p>")
L
.marker([
39.224,
-76.856
])
.addTo( map )
.bindPopup("<p>Vantage House <p>")
L
.marker([
39.339,
-76.683
])
.addTo( map )
.bindPopup("<p>Arlington West Nursing and Rehabilitation Center<p>")
L
.marker([
39.329,
-76.542
])
.addTo( map )
.bindPopup("<p>Brinton Woods Post Acute Care Center<p>")
L
.marker([
39.274,
-76.734
])
.addTo( map )
.bindPopup("<p>Catonsville Commons<p>")
L
.marker([
39.266,
-76.703
])
.addTo( map )
.bindPopup("<p>Charlestown Community Inc. <p>")
L
.marker([
39.374,
-76.724
])
.addTo( map )
.bindPopup("<p>Envoy of Pikesville <p>")
L
.marker([
39.027,
-76.604
])
.addTo( map )
.bindPopup("<p>Fairfield Nursing & Rehabilitation Center<p>")
L
.marker([
39.287,
-76.722
])
.addTo( map )
.bindPopup("<p>Frederick Villa Nursing & Rehabilitation Center<p>")
L
.marker([
38.961,
-76.56
])
.addTo( map )
.bindPopup("<p>Ginger Cove<p>")
L
.marker([
39.387,
-76.624
])
.addTo( map )
.bindPopup("<p>Greater Baltimore Medical Center Sub Acute Unit<p>")
L
.marker([
38.973,
-76.587
])
.addTo( map )
.bindPopup("<p>Heritage Harbor Health & Rehabilitation Center<p>")
L
.marker([
39.059,
-76.648
])
.addTo( map )
.bindPopup("<p>Knollwood Manor Nursing Home<p>")
L
.marker([
39.354,
-76.663
])
.addTo( map )
.bindPopup("<p>Levindale Hebrew Ger Center & Hospital <p>")
L
.marker([
39.264,
-76.7
])
.addTo( map )
.bindPopup("<p>Little Sisters of the Poor<p>")
L
.marker([
39.37,
-77.153
])
.addTo( map )
.bindPopup("<p>Lorien Health Systems - Mt. Airy<p>")
L
.marker([
39.479,
-76.246
])
.addTo( map )
.bindPopup("<p>Lorien Health Systems - Riverside<p>")
L
.marker([
39.46,
-76.664
])
.addTo( map )
.bindPopup("<p>Lorien Mays Chapel<p>")
L
.marker([
39.197,
-76.885
])
.addTo( map )
.bindPopup("<p>Lorien Health Systes - Columbia<p>")
L
.marker([
39.153,
-76.584
])
.addTo( map )
.bindPopup("<p>Marley Neck Health & Rehabilitation Center<p>")
L
.marker([
39.34,
-76.721
])
.addTo( map )
.bindPopup("<p>Milford Manor Nursing Home<p>")
L
.marker([
39.39,
-76.606
])
.addTo( map )
.bindPopup("<p>Multi-Medical Center <p>")
L
.marker([
39.335,
-76.451
])
.addTo( map )
.bindPopup("<p>Oakwood Care Center<p>")
L
.marker([
39.406,
-76.623
])
.addTo( map )
.bindPopup("<p>Pickersgill Retirement Community <p>")
L
.marker([
39.383,
-77.275
])
.addTo( map )
.bindPopup("<p>Pleasant View Nursing Home <p>")
L
.marker([
39.082,
-76.57
])
.addTo( map )
.bindPopup("<p>Severna Park Center<p>")
L
.marker([
38.961,
-76.503
])
.addTo( map )
.bindPopup("<p>Spa Creek Center<p>")
L
.marker([
39.452,
-76.593
])
.addTo( map )
.bindPopup("<p>Stella Maris, Inc. <p>")
L
.marker([
38.964,
-76.475
])
.addTo( map )
.bindPopup("<p>The Arbor<p>")
L
.marker([
39.274,
-76.673
])
.addTo( map )
.bindPopup("<p>Caton Manor <p>")
L
.marker([
39.559,
-76.374
])
.addTo( map )
.bindPopup("<p>Forest Hill Health & Rehabilitation Center<p>")
L
.marker([
39.304,
-76.712
])
.addTo( map )
.bindPopup("<p>Franklin Woods Center <p>")
L
.marker([
39.201,
-76.642
])
.addTo( map )
.bindPopup("<p>Glen Burnie Health & Rehabilitation Center<p>")
L
.marker([
39.213,
-76.627
])
.addTo( map )
.bindPopup("<p>Hammonds Lane Center<p>")
L
.marker([
39.4,
-76.559
])
.addTo( map )
.bindPopup("<p>Loch Raven Center <p>")
L
.marker([
39.367,
-76.618
])
.addTo( map )
.bindPopup("<p>Long Green Center<p>")
L
.marker([
39.369,
-76.8
])
.addTo( map )
.bindPopup("<p>Patapsco Valley Center<p>")
L
.marker([
39.407,
-76.666
])
.addTo( map )
.bindPopup("<p>Powerback Rehabilitation<p>")
L
.marker([
39.282,
-76.716
])
.addTo( map )
.bindPopup("<p>Ridgeway Manor Nursing & Rehabilitation Center<p>")
L
.marker([
39.288,
-76.529
])
.addTo( map )
.bindPopup("<p>Riverview Rehabilitation & Health Center<p>")
L
.marker([
38.938,
-76.56
])
.addTo( map )
.bindPopup("<p>South River Health & Rehabilitation Center<p>")
L
.marker([
39.269,
-76.747
])
.addTo( map )
.bindPopup("<p>Summit Park Health & Rehabilitation Center<p>")
L
.marker([
39.353,
-76.667
])
.addTo( map )
.bindPopup("<p>Blue Point Nursing & Rehabilitation Center<p>")
L
.marker([
39.328,
-76.686
])
.addTo( map )
.bindPopup("<p>Bridgepark Healthcare Center - Frm Liberty Heights<p>")
L
.marker([
39.549,
-77.018
])
.addTo( map )
.bindPopup("<p>Carroll Lutheran Village<p>")
L
.marker([
39.365,
-76.75
])
.addTo( map )
.bindPopup("<p>Courtland Gardens Nursing & Rehabilitation Center<p>")
L
.marker([
39.291,
-76.819
])
.addTo( map )
.bindPopup("<p>Ellicott City Health & Rehabilitation Center<p>")
L
.marker([
39.277,
-76.733
])
.addTo( map )
.bindPopup("<p>Forest Haven Nursing Home<p>")
L
.marker([
39.28,
-76.499
])
.addTo( map )
.bindPopup("<p>Heritage Center<p>")
L
.marker([
39.384,
-76.604
])
.addTo( map )
.bindPopup("<p>Holly Hill Nursing & Rehabilitation Center<p>")
L
.marker([
39.14,
-76.626
])
.addTo( map )
.bindPopup("<p>North Arundel Health & Rehabilitation Center<p>")
L
.marker([
39.284,
-76.701
])
.addTo( map )
.bindPopup("<p>Rock Glen Nursing & Rehabilitation Center<p>")
L
.marker([
39.273,
-76.666
])
.addTo( map )
.bindPopup("<p>St. Elizabeth Rehab. & Nursing Center<p>")
L
.marker([
39.4,
-76.559
])
.addTo( map )
.bindPopup("<p>Cromwell Center<p>")
L
.marker([
39.563,
-76.986
])
.addTo( map )
.bindPopup("<p>Golden Living Center<p>")
L
.marker([
39.364,
-76.615
])
.addTo( map )
.bindPopup("<p>Homewood Center<p>")
L
.marker([
39.396,
-76.861
])
.addTo( map )
.bindPopup("<p>Mid-Atlantic of Chapel Hill, LLC<p>")
L
.marker([
39.349,
-76.537
])
.addTo( map )
.bindPopup("<p>Overlea Health & Rehabilitation Center<p>")
L
.marker([
39.324,
-76.69
])
.addTo( map )
.bindPopup("<p>Perring Parkway Center<p>")
L
.marker([
39.374,
-76.972
])
.addTo( map )
.bindPopup("<p>Transitions Healthcare of Sykesville<p>")
L
.marker([
39.546,
-76.134
])
.addTo( map )
.bindPopup("<p>Lorien Bulle Rock<p>")
L
.marker([
39.334,
-76.65
])
.addTo( map )
.bindPopup("<p>Alice Manor Nursing Home<p>")
L
.marker([
39.349,
-76.724
])
.addTo( map )
.bindPopup("<p>Augsburg Lutheran Home<p>")
L
.marker([
39.311,
-76.674
])
.addTo( map )
.bindPopup("<p>Crawford Retreat <p>")
L
.marker([
39.29,
-76.638
])
.addTo( map )
.bindPopup("<p>Fayette Health & Rehabilitation Center<p>")
L
.marker([
39.337,
-76.628
])
.addTo( map )
.bindPopup("<p>Keswick Multi-care Center<p>")
L
.marker([
39.337,
-76.632
])
.addTo( map )
.bindPopup("<p>Roland Park Place<p>")
L
.marker([
39.329,
-76.603
])
.addTo( map )
.bindPopup("<p>The Green House at Stadium Place<p>")
L
.marker([
39.229,
-76.696
])
.addTo( map )
.bindPopup("<p>Transitional Care Services at Mercy Medical Center<p>")
L
.marker([
39.41,
-76.624
])
.addTo( map )
.bindPopup("<p>Chestnut Grn Health Center Blakehur<p>")
L
.marker([
39.05,
-76.504
])
.addTo( map )
.bindPopup("<p>Future Care Chesapeake<p>")
L
.marker([
39.624,
-77.761
])
.addTo( map )
.bindPopup("<p>Broadmead<p>")
L
.marker([
39.236,
-76.942
])
.addTo( map )
.bindPopup("<p>Encore at Turf Valley <p>")
L
.marker([
38.964,
-76.66
])
.addTo( map )
.bindPopup("<p>Crofton Convalescent Center<p>")
L
.marker([
39.45,
-76.819
])
.addTo( map )
.bindPopup("<p>Future Care Cherrywood<p>")
L
.marker([
39.379,
-76.971
])
.addTo( map )
.bindPopup("<p>Fairhaven, Inc. <p>")
if (spec.circle2){
for (var c in spec.circle2){
var circle = L.circle(c.center, c.radius, c.opts)
.addTo(map);
}
}
</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