使用 shinydashboard 建立儀表板
Png Kee Seng
Researcher
sf 製作空間地圖sf 的空間視覺化一律以圖層堆疊建立
sf 與 tidyversest_read() 與 st_as_sf() 讀取 KML(Keyhole Markup Language)檔london_poly:倫敦的空間「邊界」london_loop:環繞倫敦的(近乎)圓形「路徑」london_capital:連結倫敦內側各區的圓形「路徑」listings_geo:Airbnb 列表的「座標」library(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: MULTIPOLYGONDimension: 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....
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() 建立多邊形plot()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() 為 london_loop 建立折線add 設為 TRUEcol 設為藍色london_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() 繪製 sf 的圖層num_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()
使用 shinydashboard 建立儀表板