利用DataTaipei套件搜尋youBike站場相關資料集, 取得站場座標與各站空位數量等,以R 語言轉為Google Map呈現。
suppressPackageStartupMessages({ library(DataTaipei) library(dplyr) library(ggmap) })
透過dataSetMetadataSearch
,我們可取得關於youBike的搜尋結果:
rs <- dataSetMetadataSearch(q = "youbike")
由dataset中的metadata解析出resource ID
透過 resourceAquire
,我們可取得資料項目內容
rid <- getResources(rs, 1) suppressWarnings(df <- resourceAquire(rid$resourceId[1]))
在youBike相關資料中取得站場經緯度與空位數量 以R 語言 ggmap套件轉為Google Map呈現
# plot strsplit(rs$fieldDescription, "\r\n") df2 <- dplyr::mutate(df, lat = as.numeric(lat), lng = as.numeric(lng)) bdy_location <- dplyr::select(df2, lng, lat) %>% apply(MARGIN = 2, range) qmap(location = c(bdy_location[c(1, 3, 2, 4)]), zoom = 14,legend = "topleft") + geom_point(aes(x = lng, y = lat, size = bemp), colour = "blue",data = df2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.