-
Notifications
You must be signed in to change notification settings - Fork 61
/
map_leaf.Rd
160 lines (136 loc) · 4.02 KB
/
map_leaf.Rd
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mapleaflet.R
\name{map_leaf}
\alias{map_leaf}
\title{Make an interactive map locally}
\usage{
map_leaf(input, lat = NULL, lon = NULL, basemap = "Stamen.Toner", ...)
}
\arguments{
\item{input}{Input object}
\item{lat}{Name of latitude variable}
\item{lon}{Name of longitude variable}
\item{basemap}{Basemap to use. See \code{leaflet::addProviderTiles}.
Default: \code{Stamen.Toner}}
\item{...}{Further arguments passed on to \code{leaflet::addPolygons},
\code{leaflet::addMarkers}, \code{leaflet::addGeoJSON}, or \code{leaflet::addPolylines}}
}
\description{
Make an interactive map locally
}
\examples{
\dontrun{
# We'll need leaflet below
library("leaflet")
# From file
file <- "myfile.geojson"
geojson_write(us_cities[1:20, ], lat = "lat", lon = "long", file = file)
map_leaf(as.location(file))
# From SpatialPoints class
library("sp")
x <- c(1, 2, 3, 4, 20)
y <- c(3, 2, 5, 3, 4)
s <- SpatialPoints(cbind(x, y))
map_leaf(s)
# from SpatialPointsDataFrame class
x <- c(1, 2, 3, 4, 5)
y <- c(3, 2, 5, 1, 4)
s <- SpatialPointsDataFrame(cbind(x, y), mtcars[1:5, ])
map_leaf(s)
# from SpatialPolygons class
poly1 <- Polygons(list(Polygon(cbind(
c(-100, -90, -85, -100),
c(40, 50, 45, 40)
))), "1")
poly2 <- Polygons(list(Polygon(cbind(
c(-90, -80, -75, -90),
c(30, 40, 35, 30)
))), "2")
sp_poly <- SpatialPolygons(list(poly1, poly2), 1:2)
map_leaf(sp_poly)
# From SpatialPolygonsDataFrame class
sp_polydf <- as(sp_poly, "SpatialPolygonsDataFrame")
map_leaf(sp_poly)
# From SpatialLines class
c1 <- cbind(c(1, 2, 3), c(3, 2, 2))
c2 <- cbind(c1[, 1] + .05, c1[, 2] + .05)
c3 <- cbind(c(1, 2, 3), c(1, 1.5, 1))
L1 <- Line(c1)
L2 <- Line(c2)
L3 <- Line(c3)
Ls1 <- Lines(list(L1), ID = "a")
Ls2 <- Lines(list(L2, L3), ID = "b")
sl1 <- SpatialLines(list(Ls1))
sl12 <- SpatialLines(list(Ls1, Ls2))
map_leaf(sl1)
map_leaf(sl12)
# From SpatialLinesDataFrame class
dat <- data.frame(
X = c("Blue", "Green"),
Y = c("Train", "Plane"),
Z = c("Road", "River"), row.names = c("a", "b")
)
sldf <- SpatialLinesDataFrame(sl12, dat)
map_leaf(sldf)
# From SpatialGrid
x <- GridTopology(c(0, 0), c(1, 1), c(5, 5))
y <- SpatialGrid(x)
map_leaf(y)
# From SpatialGridDataFrame
sgdim <- c(3, 4)
sg <- SpatialGrid(GridTopology(rep(0, 2), rep(10, 2), sgdim))
sgdf <- SpatialGridDataFrame(sg, data.frame(val = 1:12))
map_leaf(sgdf)
# from data.frame
map_leaf(us_cities)
## another example
head(states)
map_leaf(states[1:351, ])
## From a named list
mylist <- list(
list(lat = 30, long = 120, marker = "red"),
list(lat = 30, long = 130, marker = "blue")
)
map_leaf(mylist, lat = "lat", lon = "long")
## From an unnamed list
poly <- list(
c(-114.345703125, 39.436192999314095),
c(-114.345703125, 43.45291889355468),
c(-106.61132812499999, 43.45291889355468),
c(-106.61132812499999, 39.436192999314095),
c(-114.345703125, 39.436192999314095)
)
map_leaf(poly)
## NOTE: Polygons from lists aren't supported yet
# From a json object
map_leaf(geojson_json(c(-99.74, 32.45)))
map_leaf(geojson_json(c(-119, 45)))
map_leaf(geojson_json(c(-99.74, 32.45)))
## another example
map_leaf(geojson_json(us_cities[1:10, ], lat = "lat", lon = "long"))
# From a geo_list object
(res <- geojson_list(us_cities[1:2, ], lat = "lat", lon = "long"))
map_leaf(res)
# From SpatialPixels
pixels <- suppressWarnings(SpatialPixels(SpatialPoints(us_cities[c("long", "lat")])))
summary(pixels)
map_leaf(pixels)
# From SpatialPixelsDataFrame
pixelsdf <- suppressWarnings(
SpatialPixelsDataFrame(points = canada_cities[c("long", "lat")], data = canada_cities)
)
map_leaf(pixelsdf)
# basemap toggling ------------------------
map_leaf(us_cities, basemap = "Acetate.terrain")
map_leaf(us_cities, basemap = "CartoDB.Positron")
map_leaf(us_cities, basemap = "OpenTopoMap")
# leaflet options ------------------------
map_leaf(us_cities) \%>\%
addPopups(-122.327298, 47.597131, "foo bar", options = popupOptions(closeButton = FALSE))
####### not working yet
# From a numeric vector
## of length 2 to a point
## vec <- c(-99.74,32.45)
## map_leaf(vec)
}
}