key請由課綱選: 新課綱:https://docs.google.com/document/d/1o8UQIpy6GFqCgfUxc47fqyAPuEYrk3FLd7bB1EhYMVg
knitr::opts_chunk$set(echo = TRUE, eval=F) library(drake) library(econDV) library(dplyr)
library(dplyr) library(tidyr) library(stringr) library(googledrive) library(readr) library(ggplot2) library(econDV) econDV::setup_chinese(need2Knit = F) rprojroot::is_rstudio_project -> .pj .pj$make_fix_file() -> .root imageFolder <- file.path(.root(),"img") dataFolder <- file.path(.root(),"data") if(!dir.exists(imageFolder)) dir.create(imageFolder) if(!dir.exists(dataFolder)) dir.create(dataFolder) library(osmdata) library(sf) library(ggmap) xfun::download_file("https://www.dropbox.com/s/7b3nbgfx5bgft8g/drake_annotationmaps.Rdata?dl=1") load("drake_annotationmaps.Rdata") xfun::download_file("https://www.dropbox.com/s/8ndtvzqbdb4cb93/data_visulaization_pk.R?dl=1") source("data_visulaization_pk.R", encoding = "UTF-8") drake$.updateCache() drake$source_plan() drake$makePlan()
election2020 = jsonlite::fromJSON( "https://www.dropbox.com/s/a3torx0p41hheb6/presidentElection2020.json?dl=1" ) names(election2020) %>% stringr::str_which("\\(1|2|3\\)") %>% { names(election2020)[.] <- c("kmt", "np", "dpp") election2020 } -> election2020_rename
drake$loadTarget$dsf_newTaipei()
data1 %>% left/right_join( data2, by=c("nameInData1"="nameInData2") )
dsf_newTaipei$osm_multipolygons %>% osm_geom_rename() -> dsf_newTaipei2 dsf_newTaipei2 %>% left_join( election2020_rename %>% select(dpp, "鄉(鎮、市、區)別"), by=c("name"="鄉(鎮、市、區)別") ) -> dsf_newTaipeiDPP
dsf_newTaipeiDPP %>% na.omit() %>% ggplot() + geom_sf(aes(fill=dpp), color="white", size=0.2) -> ggsf_election2020
drake$loadTarget$newTaipeiBBox2()
newTaipei_tonerlite <- get_map(newTaipeiBBox2, maptype="toner-lite")
ggmap_newTaipeiTonerLite <- ggmap(newTaipei_tonerlite)
ggmap_newTaipeiTonerLite
ggmap_newTaipeiTonerLite + geom_sf( data=dsf_newTaipeiDPP %>% na.omit(), mapping=aes(fill=dpp), color="white", size=0.2, alpha=0.7, inherit.aes = FALSE # make sure this setup ) + theme_void() -> ggmap_election2020_1
ggmap_election2020_1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.