pacman::p_load(
ggplot2,
osmdata
)
available_features()
## [1] "4wd_only" "abandoned"
## [3] "abutters" "access"
## [5] "addr" "addr:city"
## [7] "addr:conscriptionnumber" "addr:country"
## [9] "addr:county" "addr:district"
## [11] "addr:flats" "addr:full"
## [13] "addr:hamlet" "addr:housename"
## [15] "addr:housenumber" "addr:inclusion"
## [17] "addr:interpolation" "addr:place"
## [19] "addr:postbox" "addr:postcode"
## [21] "addr:province" "addr:state"
## [23] "addr:street" "addr:subdistrict"
## [25] "addr:suburb" "addr:unit"
## [27] "admin_level" "aeroway"
## [29] "agricultural" "alt_name"
## [31] "amenity" "area"
## [33] "atv" "backward"
## [35] "barrier" "basin"
## [37] "bdouble" "bicycle"
## [39] "bicycle_road" "biergarten"
## [41] "boat" "border_type"
## [43] "boundary" "brand"
## [45] "bridge" "building"
## [47] "building:colour" "building:fireproof"
## [49] "building:flats" "building:levels"
## [51] "building:material" "building:min_level"
## [53] "building:part" "building:soft_storey"
## [55] "bus_bay" "busway"
## [57] "capacity" "castle_type"
## [59] "change" "charge"
## [61] "clothes" "construction"
## [63] "construction#Railways" "construction_date"
## [65] "covered" "craft"
## [67] "crossing" "crossing:island"
## [69] "cuisine" "cutting"
## [71] "cycleway" "denomination"
## [73] "destination" "diet:*"
## [75] "direction" "dispensing"
## [77] "disused" "drinking_water"
## [79] "drive_in" "drive_through"
## [81] "ele" "electric_bicycle"
## [83] "electrified" "embankment"
## [85] "embedded_rails" "emergency"
## [87] "end_date" "entrance"
## [89] "est_width" "fee"
## [91] "female" "fire_object:type"
## [93] "fire_operator" "fire_rank"
## [95] "food" "foot"
## [97] "footway" "ford"
## [99] "forestry" "forward"
## [101] "frequency" "fuel"
## [103] "gauge" "golf_cart"
## [105] "goods" "hazard"
## [107] "hazmat" "healthcare"
## [109] "healthcare:counselling" "healthcare:speciality"
## [111] "height" "hgv"
## [113] "highway" "historic"
## [115] "horse" "hot_water"
## [117] "ice_road" "incline"
## [119] "industrial" "inline_skates"
## [121] "inscription" "int_name"
## [123] "internet_access" "junction"
## [125] "kerb" "landuse"
## [127] "lanes" "lanes:bus"
## [129] "lanes:psv" "layer"
## [131] "leaf_cycle" "leaf_type"
## [133] "leisure" "lhv"
## [135] "lit" "loc_name"
## [137] "location" "male"
## [139] "man_made" "max_age"
## [141] "max_level" "maxaxleload"
## [143] "maxheight" "maxlength"
## [145] "maxspeed" "maxstay"
## [147] "maxweight" "maxwidth"
## [149] "military" "min_age"
## [151] "min_level" "minspeed"
## [153] "mofa" "moped"
## [155] "motor_vehicle" "motorboat"
## [157] "motorcar" "motorcycle"
## [159] "motorroad" "mountain_pass"
## [161] "mtb:description" "mtb:scale"
## [163] "name" "name:left"
## [165] "name:right" "name_1"
## [167] "name_2" "narrow"
## [169] "nat_name" "natural"
## [171] "nickname" "noexit"
## [173] "nudism" "office"
## [175] "official_name" "old_name"
## [177] "oneway" "oneway:bicycle"
## [179] "opening_hours" "opening_hours:drive_through"
## [181] "operator" "operator:type"
## [183] "orientation" "oven"
## [185] "overtaking" "parking"
## [187] "parking:condition" "parking:lane"
## [189] "passing_places" "place"
## [191] "power" "power_supply"
## [193] "priority" "priority_road"
## [195] "produce" "proposed"
## [197] "protected_area" "psv"
## [199] "public_transport" "railway"
## [201] "railway:preserved" "railway:track_ref"
## [203] "recycling_type" "ref"
## [205] "reg_name" "religion"
## [207] "rental" "residential"
## [209] "roadtrain" "route"
## [211] "sac_scale" "sauna"
## [213] "service" "service_times"
## [215] "shelter_type" "shop"
## [217] "short_name" "shower"
## [219] "sidewalk" "site"
## [221] "ski" "smoothness"
## [223] "social_facility" "sorting_name"
## [225] "speed_pedelec" "start_date"
## [227] "step_count" "substation"
## [229] "surface" "tactile_paving"
## [231] "tank" "tidal"
## [233] "toilets" "toilets:wheelchair"
## [235] "toll" "topless"
## [237] "tourism" "tracks"
## [239] "tracktype" "traffic_calming"
## [241] "traffic_sign" "trail_visibility"
## [243] "trailblazed" "trailblazed:visibility"
## [245] "tunnel" "turn"
## [247] "type" "unisex"
## [249] "usage" "vehicle"
## [251] "vending" "voltage"
## [253] "water" "wheelchair"
## [255] "wholesale" "width"
## [257] "winter_road" "wood"
available_tags("highway") # all types of streets that OpenStreetMap highway saves
## # A tibble: 53 × 2
## Key Value
## <chr> <chr>
## 1 highway bridleway
## 2 highway bus_guideway
## 3 highway bus_stop
## 4 highway busway
## 5 highway construction
## 6 highway corridor
## 7 highway crossing
## 8 highway cycleway
## 9 highway elevator
## 10 highway emergency_access_point
## # ℹ 43 more rows
getbb <- "glasgow uk"
# streets
streets <- getbb("glasgow uk") %>%
opq() %>%
add_osm_feature(key = "highway",
value = c("motorway", "primary",
"secondary", "tertiary")) %>%
osmdata_sf()
streets
## Object of class 'osmdata' with:
## $bbox : 55.701155,-4.4101687,56.021155,-4.0901687
## $overpass_call : The call submitted to the overpass API
## $meta : metadata including timestamp and version numbers
## $osm_points : 'sf' Simple Features Collection with 44710 points
## $osm_lines : 'sf' Simple Features Collection with 6170 linestrings
## $osm_polygons : 'sf' Simple Features Collection with 184 polygons
## $osm_multilines : NULL
## $osm_multipolygons : NULL
# river
river <- getbb("glasgow uk") %>%
opq() %>%
add_osm_feature(key = "waterway",
value = "river") %>%
osmdata_sf()
# street only
ggplot() +
geom_sf(data = streets$osm_lines,
inherit.aes = FALSE,
color = "black",
size = .4,
alpha = .8) +
coord_sf(expand = FALSE) # expand = FALSE you make sure that the coordinates are displayed exactly
ggplot() +
geom_sf(data = streets$osm_lines, # street
inherit.aes = FALSE,
color = "black",
size = .4,
alpha = .8) +
geom_sf(data = river$osm_lines, # river
inherit.aes = FALSE,
color = "#7fc0ff",
size = .2,
alpha = .9) +
coord_sf(xlim = c(-4.45, -4.00),
ylim = c(55.70, 56.00),
expand = FALSE) +
theme_void() + # get rid of background color, grid lines, etc.
theme(plot.title = element_text(size = 14, family = "arial", face = "bold", hjust = .5),
plot.subtitle = element_text(family = "lato", size = 8, hjust = .5, margin = margin(2, 0, 5, 0))) +
labs(title = "GLASGOW, SCOTLAND", subtitle = "55.860916°N /-4.251433°W")
Let’s add the remaining features as well as some coloring, size, and alpha aesthetics
# street and river
ggplot() +
geom_sf(data = streets$osm_lines,
inherit.aes = FALSE,
color = "#ffbe7f",
size = .4,
alpha = .8) +
geom_sf(data = river$osm_lines,
inherit.aes = FALSE,
color = "#7fc0ff",
size = .2,
alpha = .5) +
coord_sf(xlim = c(-4.45, -4.00),
ylim = c(55.70, 56.00),
expand = FALSE) +
theme_void() +
theme(plot.title = element_text(size = 14, colour = "grey", face = "bold", hjust = .5),
plot.subtitle = element_text(colour = "grey", size = 8, hjust = .5, margin = margin(2, 0, 5, 0))) +
theme(plot.background = element_rect(fill = "#282828")) +
labs(title = "GLASGOW, SCOTLAND", subtitle = "55.860916°N /-4.251433°W")