Building Dashboards with shinydashboard
Png Kee Seng
Researcher
sf
to create geospatial mapssf
geospatial visualization is always created in layerssf
and tidyverse
st_read()
and st_as_sf()
to read keyhole markup language (KML) fileslondon_poly
: geospatial boundaries of Londonlondon_loop
: circular (almost) path surrounding Londonlondon_capital
: circular path linking parts of inner Londonlistings_geo
: coordinates of Airbnb listingslibrary(sf)
library(tidyverse)
london_poly <- st_read("../data/london_boroughs_boroughs_kml.kml",
drivers = "KML", quiet=TRUE)
london_loop <- st_read("../data/London-Loop-SWC-Walk-L24.kml",
drivers = "KML", quiet=TRUE)
london_capital <- st_read("../data/Capital-Ring-SWC-Walk-L23.kml",
drivers="KML", quiet=TRUE)
listings_geo <- st_as_sf(listings,
coords = c("longitude", "latitude"))
london_poly$geometry
Geometry set for 33 features Geometry type: MULTIPOLYGON
Dimension: XY Bounding box: xmin: -0.508813 ymin: 51.28691 ... Geodetic CRS: WGS 84 First 5 geometries: MULTIPOLYGON (((-0.183361 51.66868, -0.183383 5... MULTIPOLYGON (((0.158044 51.50904, 0.156309 51.... MULTIPOLYGON (((-0.212138 51.55558, -0.212689 5... MULTIPOLYGON (((0.076463 51.431, 0.075932 51.43... MULTIPOLYGON (((-0.140804 51.56946, -0.14081 51...
london_loop$geometry
Geometry set for 1 feature
Geometry type: LINESTRING
Dimension: XYZ
Bounding box: xmin: -0.499406 ymin: 51.29375 xmax: 0.257656 ymax: 51.67563
z_range: zmin: 0 zmax: 174
Geodetic CRS: WGS 84
LINESTRING Z (0.236477 51.48095 1, 0.235149 51....
Same for london_capital
listings_geo$geometry
Geometry set for 69351 features
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -0.5236 ymin: 51.27248 xmax: 0.30515 ymax: 51.70893
CRS: NA
First 5 geometries:
POINT (-0.05396 51.52874)
POINT (-0.1127 51.56861)
POINT (-0.07426 51.52851)
POINT (-0.10484 51.52478)
POINT (-0.20004 51.51464)
st_geometry()
to create polygonsplot()
col
plot(st_geometry(london_poly), axes=TRUE,
border=grey(0.2, 0.5))
plot(st_geometry(london_poly),
col = sf.colors(length(london_poly$Name),
categorical = TRUE),
axes=TRUE, border=grey(0.2, 0.5))
st_geometry()
to create polylines for london_loop
add
to TRUE
col
to bluelondon_capital
plot(st_geometry(london_loop),
add=TRUE,
col="blue")
plot(st_geometry(london_capital), add=TRUE, col="darkgreen")
st_geometry()
plot(st_geometry(listings_geo), add=TRUE, col='red')
ggplot()
to plot layers of sfnum_listings <- listings %>% group_by(neighbourhood) %>% summarize(`Number of listings` = n(), longitude = mean(longitude), latitude = mean(latitude), .groups = "drop") %>%
st_as_sf(coords = c("longitude", "latitude"))
st_crs(num_listings) <- st_crs(london_poly)
ggplot_map <- ggplot(london_poly) + geom_sf(aes(fill = Name)) +
geom_sf_label(data=num_listings, aes(label=`Number of listings`)) + theme_classic()
Building Dashboards with shinydashboard