-
Notifications
You must be signed in to change notification settings - Fork 10
/
leaftlet_run_through.Rmd
124 lines (83 loc) · 2.46 KB
/
leaftlet_run_through.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: "leaftlet_runthrough"
author: "Maggie Klope"
date: "2/9/2022"
output: html_document
---
## Leaflet: Easily create interactive maps
- Uses the [Leaflet](https://leafletjs.com/index.html) open-source JavaScript library
- Quick way to make interactive maps
- Can be embedded into R Markdown and Shiny apps
- Compatible with a lot of data types (data frames with lat/long columns, sp and sf package spatial objects)
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# install packages if you have not already
# install.packages("tidyverse")
# install.packages("leaflet")
# install.packages("leaflet.minicharts")
# install.packages("sf")
library(tidyverse)
library(leaflet)
library(leaflet.minicharts)
library(sf)
```
### Basic Map with one point
```{r}
# Using the lat/long for the Methuselah Tree (oldest non-clonal tree in the world!)
methuselah <-
# adding more features
# lots of different privider tiles: https://leaflet-extras.github.io/leaflet-providers/preview/
methuselah %>% addProviderTiles(providers$Esri.WorldImagery)
methuselah %>% addProviderTiles(providers$Stamen.Watercolor)
```
### Using shapefile
- Audubon Society occurrence surveys
- Includes a count of sensitive and threatened species
- Assigns a Score value for the taxa that exceed the population threshold of 1% of global or 10% of state population
```{r}
# use sf to read the shapefile
birds <-
# creating a point map
bird_map <-
```
### Creating a cluster map
```{r}
```
### Creating custom icons
```{r}
# making a dataset for locations where brown pelicans (BRPN) were detected
pelicans <-
# using the makeIcon() function to load a .png file
pelican_icon <-
# creating map with custom icon
```
### Using the leaflet.minicharts package, you can add figures over your map
```{r}
bird_matrix <- as.tibble(birds)
# adding barcharts
leaflet(data = bird_matrix) %>%
addTiles() %>%
addMinicharts(
lng = bird_matrix$LONGITUDE,
lat = bird_matrix$LATITUDE,
chartdata = bird_matrix[, c("SCORE", "THREAT")],# just using the Score and Threat columns
type = "bar")
# adding piecharts
# adding label
```
### Maps with Polylines
```{r}
# loading example dataset from the leaflet package
storm_data <- atlStorms2005
# Create a continuous palette function
palette <-
# Creating a map
storm <-
storm
# some extra features
storm %>%
addGraticule() %>%
addTerminator()
```
### Compatible with Shiny
- See the leaflet_shiny_app.R file