Skip to content

Commit 4fe89b9

Browse files
committed
update plotting xy
1 parent b51833c commit 4fe89b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+9241
-589
lines changed

01_georeference.Rmd

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ output: html_document
66
---
77
 
88

9-
Introducing the `library(leaflet)` Use 5 lines of code to make an interactive map (Adapted from Machlis.)^[[5 Visualizations in 5 Minutes](http://www.computerworld.com/article/2893271/business-intelligence/5-data-visualizations-in-5-minutes-each-in-5-lines-or-less-of-r.html). ComputerWorld.com by Sharon Machlis]
9+
To introduce the `library(mapview)` package, make an interactive map with Starbucks coffee shop locations in North Carolina (2012). (Adapted from Machlis.)^[[5 Visualizations in 5 Minutes](http://www.computerworld.com/article/2893271/business-intelligence/5-data-visualizations-in-5-minutes-each-in-5-lines-or-less-of-r.html). ComputerWorld.com by Sharon Machlis]
1010

1111

1212
## Load Libraries
1313

1414
```{r libraries, message=FALSE, warning=FALSE}
1515
library(tidyverse)
16+
library(sf)
1617
library(leaflet)
18+
library(mapview)
1719
```
1820

1921
## Load Data
@@ -32,18 +34,28 @@ starbucksNC <- starbucks %>%
3234
starbucksNC
3335
```
3436

37+
## Transform to Spatial Data
3538

36-
## Plot Lat and Lon on a Map
39+
Transform our standard tibble (i.e. the starbucksNC data frame) into a spacial data frame via the simple features function, `st_as_sf()`. Here we set the [map projection](https://en.wikipedia.org/wiki/Map_projection) to a common standard, WGS84, via the argument `crs = 4326`.)
3740

38-
Using the `leaflet` function, plot the latitude and longitude on a basemap. Latitude is *Y*, Longitude is *X*.
41+
```{r convert2spacial}
42+
sbuxsfc <- st_as_sf(starbucksNC, coords = c("Longitude", "Latitude"), crs=4326)
43+
```
44+
45+
Below, you can set the `map.types` argument to `openStreetMap`. Base maps are set with `map.types`. For example a high contrast, black and white basemap can be set with the argument `map.types = "Stamen.Toner"`. See avaiable [map types](http://leaflet-extras.github.io/leaflet-providers/preview/), or leave out the map.types argument for a set of default base maps to choose via the layering button.
3946

4047
```{r plotmap}
41-
starbucksNC %>%
42-
leaflet(width = "100%") %>%
43-
addTiles() %>%
44-
setView(-78.8310, 35.9867, zoom = 10) %>%
45-
addMarkers(lat = ~Latitude,
46-
lng = ~Longitude,
47-
popup = starbucksNC$Name)
48+
#mapview(sbuxsfc, map.types = "Stamen.Toner")
49+
mapview(sbuxsfc)
4850
```
4951

52+
53+
54+
## Save the Map
55+
56+
You can save a map as an interalctive HTML page or a static `.png, .pdf, or .jpeg` file with the [`mapshot` function](https://r-spatial.github.io/mapview/reference/mapshot.html). For example:
57+
58+
- `mapshot(starNCmap, file = "map.png")`
59+
- `mapshot(starNCmap, url = "map.html")`
60+
61+

_site.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exclude:
66
navbar:
77
title: Mapping in R
88
left:
9-
- text: "Home"
9+
- text: "Preface"
1010
menu:
1111
- text: "Overview"
1212
href: index.html
@@ -15,11 +15,7 @@ navbar:
1515
- text: "Next Steps"
1616
href: next.html
1717
- text: "Plot Coordinates"
18-
menu:
19-
- text: Interactive map (leaflet)
20-
href: 01_georeference.html
21-
- text: Static Map (ggmap)
22-
href: 01_ggmap_georef.html
18+
href: 01_georeference.html
2319
- text: "tidycensus"
2420
href: 02_choropleth.html
2521
- text: "Thematic Mapping"

docs/01_georeference.html

Lines changed: 153 additions & 21 deletions
Large diffs are not rendered by default.

docs/01_ggmap_georef.html

Lines changed: 126 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
<script src="site_libs/navigation-1.1/tabsets.js"></script>
2626
<link href="site_libs/pagedtable-1.1/css/pagedtable.css" rel="stylesheet" />
2727
<script src="site_libs/pagedtable-1.1/js/pagedtable.js"></script>
28-
<link href="site_libs/font-awesome-5.0.13/css/fa-svg-with-js.css" rel="stylesheet" />
29-
<script src="site_libs/font-awesome-5.0.13/js/fontawesome-all.min.js"></script>
30-
<script src="site_libs/font-awesome-5.0.13/js/fa-v4-shims.min.js"></script>
28+
<link href="site_libs/font-awesome-5.1.0/css/all.css" rel="stylesheet" />
29+
<link href="site_libs/font-awesome-5.1.0/css/v4-shims.css" rel="stylesheet" />
3130

3231

3332
<style type="text/css">code{white-space: pre;}</style>
34-
<style type="text/css">
33+
<style type="text/css" data-origin="pandoc">
3534
div.sourceCode { overflow-x: auto; }
3635
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
3736
margin: 0; padding: 0; vertical-align: baseline; border: none; }
@@ -67,7 +66,29 @@
6766
code > span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
6867
code > span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
6968
code > span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
69+
7070
</style>
71+
<script>
72+
// apply pandoc div.sourceCode style to pre.sourceCode instead
73+
(function() {
74+
var sheets = document.styleSheets;
75+
for (var i = 0; i < sheets.length; i++) {
76+
if (sheets[i].ownerNode.dataset["origin"] !== "pandoc") continue;
77+
try { var rules = sheets[i].cssRules; } catch (e) { continue; }
78+
for (var j = 0; j < rules.length; j++) {
79+
var rule = rules[j];
80+
// check if there is a div.sourceCode rule
81+
if (rule.type !== rule.STYLE_RULE || rule.selectorText !== "div.sourceCode") continue;
82+
var style = rule.style.cssText;
83+
// check if color or background-color is set
84+
if (rule.style.color === '' || rule.style.backgroundColor === '') continue;
85+
// replace div.sourceCode by a pre.sourceCode rule
86+
sheets[i].deleteRule(j);
87+
sheets[i].insertRule('pre.sourceCode{' + style + '}', j);
88+
}
89+
}
90+
})();
91+
</script>
7192
<style type="text/css">
7293
pre:not([class]) {
7394
background-color: white;
@@ -132,6 +153,9 @@
132153
button.code-folding-btn:focus {
133154
outline: none;
134155
}
156+
summary {
157+
display: list-item;
158+
}
135159
</style>
136160

137161

@@ -146,7 +170,6 @@
146170
padding-top: 65px;
147171
margin-top: -65px;
148172
}
149-
150173
.section h2 {
151174
padding-top: 65px;
152175
margin-top: -65px;
@@ -167,6 +190,43 @@
167190
padding-top: 65px;
168191
margin-top: -65px;
169192
}
193+
.dropdown-submenu {
194+
position: relative;
195+
}
196+
.dropdown-submenu>.dropdown-menu {
197+
top: 0;
198+
left: 100%;
199+
margin-top: -6px;
200+
margin-left: -1px;
201+
border-radius: 0 6px 6px 6px;
202+
}
203+
.dropdown-submenu:hover>.dropdown-menu {
204+
display: block;
205+
}
206+
.dropdown-submenu>a:after {
207+
display: block;
208+
content: " ";
209+
float: right;
210+
width: 0;
211+
height: 0;
212+
border-color: transparent;
213+
border-style: solid;
214+
border-width: 5px 0 5px 5px;
215+
border-left-color: #cccccc;
216+
margin-top: 5px;
217+
margin-right: -10px;
218+
}
219+
.dropdown-submenu:hover>a:after {
220+
border-left-color: #ffffff;
221+
}
222+
.dropdown-submenu.pull-left {
223+
float: none;
224+
}
225+
.dropdown-submenu.pull-left>.dropdown-menu {
226+
left: -100%;
227+
margin-left: 10px;
228+
border-radius: 6px 0 6px 6px;
229+
}
170230
</style>
171231

172232
<script>
@@ -187,21 +247,80 @@
187247
});
188248
</script>
189249

190-
191250
<div class="container-fluid main-container">
192251

193252
<!-- tabsets -->
253+
254+
<style type="text/css">
255+
.tabset-dropdown > .nav-tabs {
256+
display: inline-table;
257+
max-height: 500px;
258+
min-height: 44px;
259+
overflow-y: auto;
260+
background: white;
261+
border: 1px solid #ddd;
262+
border-radius: 4px;
263+
}
264+
265+
.tabset-dropdown > .nav-tabs > li.active:before {
266+
content: "";
267+
font-family: 'Glyphicons Halflings';
268+
display: inline-block;
269+
padding: 10px;
270+
border-right: 1px solid #ddd;
271+
}
272+
273+
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
274+
content: "&#xe258;";
275+
border: none;
276+
}
277+
278+
.tabset-dropdown > .nav-tabs.nav-tabs-open:before {
279+
content: "";
280+
font-family: 'Glyphicons Halflings';
281+
display: inline-block;
282+
padding: 10px;
283+
border-right: 1px solid #ddd;
284+
}
285+
286+
.tabset-dropdown > .nav-tabs > li.active {
287+
display: block;
288+
}
289+
290+
.tabset-dropdown > .nav-tabs > li > a,
291+
.tabset-dropdown > .nav-tabs > li > a:focus,
292+
.tabset-dropdown > .nav-tabs > li > a:hover {
293+
border: none;
294+
display: inline-block;
295+
border-radius: 4px;
296+
}
297+
298+
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
299+
display: block;
300+
float: none;
301+
}
302+
303+
.tabset-dropdown > .nav-tabs > li {
304+
display: none;
305+
}
306+
</style>
307+
194308
<script>
195309
$(document).ready(function () {
196310
window.buildTabsets("TOC");
197311
});
312+
313+
$(document).ready(function () {
314+
$('.tabset-dropdown > .nav-tabs > li').click(function () {
315+
$(this).parent().toggleClass('nav-tabs-open')
316+
});
317+
});
198318
</script>
199319

200320
<!-- code folding -->
201321

202322

203323

204-
205324
<script>
206325
$(document).ready(function () {
207326

0 commit comments

Comments
 (0)