if (FALSE) {
library(stars)
key = readLines("~/key")
# Using coordinates
r = mp_map("31.253205,34.791914", 14, key = key)
plot(r)
# Using 'sfc' point - WGS84
pnt = st_point(c(34.791914, 31.253205))
pnt = st_sfc(pnt, crs = 4326)
r = mp_map(pnt, 14, key = key)
plot(r)
# Using 'sfc' point - UTM
pnt = st_point(c(34.791914, 31.253205))
pnt = st_sfc(pnt, crs = 4326)
pnt = st_transform(pnt, 32636)
r = mp_map(pnt, 14, key = key)
plot(r)
# Using 'sfc' polygon
pnt = st_point(c(34.791914, 31.253205))
pnt = st_sfc(pnt, crs = 4326)
pol = st_buffer(pnt, 0.01)
r = mp_map(pol, 14, key = key)
plot(r)
# 'ggplot2'
library(ggplot2)
cols = attr(r[[1]], "colors")
ggplot() +
geom_stars(data = r, aes(x = x, y = y, fill = color)) +
scale_fill_manual(values = cols, guide = FALSE) +
coord_sf()
# 'ggplot2' - map types
r1 = mp_map(pnt, 14, maptype = "roadmap", key = key)
r2 = mp_map(pnt, 14, maptype = "satellite", key = key)
r3 = mp_map(pnt, 14, maptype = "terrain", key = key)
r4 = mp_map(pnt, 14, maptype = "hybrid", key = key)
cols1 = attr(r1[[1]], "colors")
cols2 = attr(r2[[1]], "colors")
cols3 = attr(r3[[1]], "colors")
cols4 = attr(r4[[1]], "colors")
theme1 = theme(
axis.text = element_blank(),
axis.title = element_blank(),
axis.ticks = element_blank()
)
g1 = ggplot() +
geom_stars(data = r1, aes(x = x, y = y, fill = color)) +
scale_fill_manual(values = cols1, guide = FALSE) +
coord_sf() +
ggtitle("roadmap") +
theme1
g2 = ggplot() +
geom_stars(data = r2, aes(x = x, y = y, fill = color)) +
scale_fill_manual(values = cols2, guide = FALSE) +
coord_sf() +
ggtitle("satellite") +
theme1
g3 = ggplot() +
geom_stars(data = r3, aes(x = x, y = y, fill = color)) +
scale_fill_manual(values = cols3, guide = FALSE) +
coord_sf() +
ggtitle("terrain") +
theme1
g4 = ggplot() +
geom_stars(data = r4, aes(x = x, y = y, fill = color)) +
scale_fill_manual(values = cols4, guide = FALSE) +
coord_sf() +
ggtitle("hybrid") +
theme1
g1 + g2 + g3 + g4
# styled maps
nl = list(
c(feature = 'all', element = 'labels', visibility = 'off')
)
nb = list(
c(feature = 'poi.business', visibility = 'off'),
c(feature = 'poi.medical', visibility = 'off')
)
r_nl = mp_map(pnt, 14, key = key, style = nl)
plot(r_nl)
r_nb = mp_map(pnt, 14, key = key, style = nb)
plot(r_nb)
}
Run the code above in your browser using DataLab