Maps of Zaragoza

Column

Streets

Streets and highways / roads

Column

Rivers

Cycleway

Column

BBVA Bank Branches

Tobbaconist´s

Zaragoza

Map of Zaragoza

London

Cycleways in London

Paris

Cycleways in Paris

Amsterdam

Cycleways in Amsterdam

México D.F.

México D.F.

---
title: "OpenStreetMaps with {osmdata}"
output: 
  flexdashboard::flex_dashboard:
    storyboard: true
    orientation: columns
    source_code: embed
    vertical_layout: fill
    theme: paper
---



```{r setup, include=FALSE}


# PACKAGES / LIBRARIES:

library(flexdashboard)
library(tidyverse)
library(osmdata)

options(scipen=10000)


# The command to check the available categories is: available_features()
# (there is more info about the categories in: https://wiki.openstreetmap.org/wiki/Map_Features)
# We will get a list with the primary features and the additional properties. 
# in each category we find key concepts and tags.

# for example, we can identify the key concepts of "shop", "railway" or "highway" by writing: 
# available_tags("shop"), available_tags("railway") or available_tags("highway")


# ie. shop_tags <- available_tags("shop")
## [1] "agrarian"  "alcohol"   "anime"     "antiques"  "appliance" "art"



# ie. available_tags("railway")
##  [1] "abandoned"        "buffer_stop"      "construction"     "crossing"        
##  [5] "derail"           "disused"          "funicular"        "halt"            
##  [9] "level_crossing"   "light_rail"       "miniature"        "monorail"        
## [13] "narrow_gauge"     "platform"         "preserved"        "rail"            
## [17] "railway_crossing" "roundhouse"       "signal"           "station"         
## [21] "subway"           "subway_entrance"  "switch"           "tram"  
## [25] "tram_stop"        "traverser"        "turntable"        "wash"



# i.e. available_tags("highway")
##  [1] "bridleway"              "bus_guideway"           "bus_stop"              
##  [4] "construction"           "corridor"               "crossing"              
##  [7] "cycleway"               "elevator"               "emergency_access_point"
## [10] "escape"                 "footway"                "give_way"              
## [13] "living_street"          "milestone"              "mini_roundabout"       
## [16] "motorway"               "motorway_junction"      "motorway_link"         
## [19] "passing_place"          "path"                   "pedestrian"            
## [22] "platform"               "primary"                "primary_link"          
## [25] "proposed"               "raceway"                "residential"           
## [28] "rest_area"              "road"                   "secondary"             
## [31] "secondary_link"         "service"                "services"              
## [34] "speed_camera"           "steps"                  "stop"                  
## [37] "street_lamp"            "tertiary"               "tertiary_link"         
## [40] "toll_gantry"            "track"                  "traffic_mirror"        
## [43] "traffic_signals"        "trailhead"              "trunk"                 
## [46] "trunk_link"             "turning_circle"         "turning_loop"          
## [49] "unclassified"

```



Maps of Zaragoza
============================================================


Column
-----------------------------------------------------------

### Streets

```{r}

# streets (calles) of Zaragoza:
# the key would be "highway"
# "residential", "living_street", "unclassified", "service" and "footway" are tags 


# streets: 

calles <- getbb("Zaragoza Spain")%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("residential", "living_street",
                            "unclassified",
                            "service", "footway")) %>%
  osmdata_sf()



# Map:

ggplot() +
  geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "darkgrey",
          size = .3,
          alpha = .8)+
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "Zaragoza")


```


### Streets and highways / roads

```{r}

# highways (carreteras) of Zaragoza: 

carreteras <- getbb("Zaragoza Spain")%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("road", "motorway", "primary", 
                            "secondary", "tertiary")) %>%
  osmdata_sf()



# Map:

ggplot() +
  geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "darkgrey",
          size = .2,
          alpha = .8)+
  geom_sf(data = carreteras$osm_lines,
          inherit.aes = FALSE,
          color = "black",
          size = .2,
          alpha = .8)+
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "Zaragoza")

```



Column
------------------------------------------------------------------

### Rivers

```{r}

# The river Ebro is one of the icons of Zaragoza. We must represent it. 
# There are other rivers (Hueva, Gallego) and canals also.


# rivers and canals:

rios <- getbb("Zaragoza Spain")%>%
  opq()%>%
  add_osm_feature(key = "waterway", 
                  value = c("river", "canal")) %>%
  osmdata_sf()



#  plot:

ggplot() +
  geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "darkgrey",
          size = .2,
          alpha = .8)+
  geom_sf(data = carreteras$osm_lines,
          inherit.aes = FALSE,
          color = "black",
          size = .2,
          alpha = .8)+
  geom_sf(data = rios$osm_lines,
          inherit.aes = FALSE,
          color = "#7fc0ff",
          size = .8,
          alpha = .8) +
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "Zaragoza")

```



### Cycleway

```{r}

# Zaragoza is one of the cities in Spain where the use of bikes has been promoted quite a lot in the last few years. (https://www.ocu.org/coches/bicicletas/noticias/bici-en-la-ciudad)
# to show the bike network we would indicate "cycleway" as tag of "highway" (key)


# cycle network:

bici <- getbb("Zaragoza Spain")%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("cycleway")) %>%
  osmdata_sf()


# plot:

ggplot() +
 geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "grey30",
          size = .4,
          alpha = .8) +
  geom_sf(data = carreteras$osm_lines,
          inherit.aes = FALSE,
          color = "grey30",
          size = .1,
          alpha = .8) +
  geom_sf(data = bici$osm_lines,
          inherit.aes = FALSE,
          color = "springgreen",
          size = .4,
          alpha = .6) +
  geom_sf(data = rios$osm_lines,
          inherit.aes = FALSE,
          color = "lightblue",
          size = .2,
          alpha = .5) +
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "Zaragoza",
       subtitle = "Cycle Network") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white"),
        plot.subtitle= element_text(colour = "white"))


```



Column
-----------------------------------------------------------

### BBVA Bank Branches

```{r}


# We can also show in the map the location of many places. 
# For example, lets indicate the location of the branches of BBVA bank in Zaragoza:


# BBVA branches:

bbva <- getbb("Zaragoza Spain")%>%
  opq()%>%
  add_osm_feature("name","BBVA")%>%
  add_osm_feature("amenity","bank") %>%
  osmdata_sf()



# plot:

ggplot() +
  geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "grey30",
          size = .4,
          alpha = .8) +
  geom_sf(data = carreteras$osm_lines,
          inherit.aes = FALSE,
          color = "grey30",
          size = .1,
          alpha = .8) +
  geom_sf(data = bbva$osm_points,
          colour = "red",
          fill = "red",
          alpha = .6,
          size = 2,
          shape = 21) +
  geom_sf(data = rios$osm_lines,
          inherit.aes = FALSE,
          color = "lightblue",
          size = .2,
          alpha = .5) +
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "Zaragoza",
       subtitle = "Branches of BBVA Bank") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white"),
        plot.subtitle= element_text(colour = "white"))


```


### Tobbaconist´s 


```{r}

# Another example: location of tobacconist´s shops in Zaragoza:


# shops:

estancos <- getbb("Zaragoza Spain")%>%
  opq()%>%
  add_osm_feature(key = "shop", 
                  value = "tobacco") %>%
  osmdata_sf()



# Plot:

ggplot() +
 geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "grey30",
          size = .4,
          alpha = .8) +
  geom_sf(data = carreteras$osm_lines,
          inherit.aes = FALSE,
          color = "grey30",
          size = .1,
          alpha = .8) +
  geom_sf(data = estancos$osm_points,
          colour="red",
          fill="red",
          alpha=.6,
          size=2,
          shape=21) +
  geom_sf(data = rios$osm_lines,
          inherit.aes = FALSE,
          color = "lightblue",
          size = .2,
          alpha = .5) +
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "Zaragoza",
       subtitle = "Tobacconist`s") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white"),
        plot.subtitle= element_text(colour = "white"))

```



Zaragoza
=======================================================

### Map of Zaragoza

```{r}

# Example of map of Zaragoza:

ggplot() +
  geom_sf(data = calles$osm_lines,
          inherit.aes = FALSE,
          color = "orange",
          size = .1,
          alpha = .8)+
  geom_sf(data = carreteras$osm_lines,
          inherit.aes = FALSE,
          color = "grey40",
          size = .2,
          alpha = .8)+
  geom_sf(data = rios$osm_lines,
          inherit.aes = FALSE,
          color = "white",
          size = .5,
          alpha = .8) +
  coord_sf(xlim = c(-0.98, -0.8), 
           ylim = c(41.6, 41.7),
           expand = FALSE) +
  theme_void() +
  labs(title = "   Zaragoza",
       subtitle = " ") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white", size = 16, hjust = 0.5))

```


London
=======================================================


### Cycleways in London

```{r}

# Let draw the cycle network of London. 
# As London is huge we can indicate the GeoCoordinates:  to represent only central London

min <- c(-0.1672, 51.4787)
max <- c(-0.0072, 51.5396)
lnd_df <- as.matrix(data.frame(min, max))
row.names(lnd_df) <- c("x","y")


# cycle network:

bike_london_2 <- lnd_df %>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("cycleway")) %>%
  osmdata_sf()


# London strets:

calles_london_2 <- lnd_df%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("residential", "living_street",
                            "unclassified",
                            "service", "footway")) %>%
  osmdata_sf()


# Plot:

ggplot(bike_london_2$osm_lines) +
  geom_sf(colour="orange",
          alpha=.5,
          size=0.5,
          shape=21)+
  geom_sf(data = calles_london_2$osm_lines,
          inherit.aes = F,
          color = "grey40",
          size = .2,
          alpha = .5)+
  theme_void() +
  labs(title = "London") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white", size = 16, hjust = 0.5))

```



Paris
===================================================================

### Cycleways in Paris

```{r}

# GeoCoordinates:  for central Paris:

min <- c(2.2680, 48.8281)
max <- c(2.4424, 48.8925)
paris_df <- as.matrix(data.frame(min, max))
row.names(paris_df) <- c("x","y")



# cycle network:

bike_paris <- paris_df %>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("cycleway")) %>%
  osmdata_sf()


# streets of Paris:

calles_paris <- paris_df%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("residential", "living_street",
                            "unclassified",
                            "service", "footway")) %>%
  osmdata_sf()


# Plot:

ggplot(bike_paris$osm_lines) +
  geom_sf(colour="orange",
          alpha=.5,
          size=0.5,
          shape=21)+
  geom_sf(data = calles_paris$osm_lines,
          inherit.aes = F,
          color = "grey40",
          size = .2,
          alpha = .5)+
  theme_void() +
  labs(title = "Paris") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white", size = 16, hjust = 0.5))

```


Amsterdam
==========================================================================


### Cycleways in Amsterdam


```{r}

# GeoCoordinates: 

min <- c(4.8573, 52.3571)
max <- c(4.9445, 52.3870)
amst_df <- as.matrix(data.frame(min, max))
row.names(amst_df) <- c("x","y")



# cycle network:

bike_amst <- amst_df %>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("cycleway")) %>%
  osmdata_sf()



# streets:

calles_amst <- amst_df%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("residential", "living_street",
                            "unclassified",
                            "service", "footway")) %>%
  osmdata_sf()


# Plot:

ggplot(bike_amst$osm_lines) +
  geom_sf(colour="orange",
          alpha=.5,
          size=0.5,
          shape=21)+
  geom_sf(data = calles_amst$osm_lines,
          inherit.aes = F,
          color = "grey40",
          size = .2,
          alpha = .5)+
  theme_void() +
  labs(title = "Amsterdam") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white", size = 16, hjust = 0.5))

```



México  D.F.
==========================================================================


### México D.F.


```{r}

# GeoCoordinates: 

min <- c(-99.2282, 19.3822)
max <- c(-99.0538, 19.4745)
mex_df <- as.matrix(data.frame(min, max))
row.names(mex_df) <- c("x","y")




# streets:

calles_mex <- mex_df%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("residential", "living_street",
                            "unclassified",
                            "service", "footway")) %>%
  osmdata_sf()



# Plot:

ggplot() +
  geom_sf(data = calles_mex$osm_lines,
          inherit.aes = F,
          color = "plum",
          size = .2,
          alpha = .5)+
  theme_void() +
  labs(title = "México D.F.") +
  theme(plot.background = element_rect(fill = "black"),
        plot.title = element_text(colour = "white", size = 16, hjust = 0.5))

```