forked from r-tmap/tmap
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
working on benchmark rmd, trying to setup gh pages
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
on: | ||
push: | ||
branches: master | ||
|
||
name: pkgdown | ||
|
||
jobs: | ||
pkgdown: | ||
runs-on: macOS-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: r-lib/actions/setup-r@master | ||
|
||
- uses: r-lib/actions/setup-pandoc@master | ||
|
||
- name: Query dependencies | ||
run: | | ||
install.packages('remotes') | ||
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) | ||
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") | ||
shell: Rscript {0} | ||
|
||
- name: Cache R packages | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ env.R_LIBS_USER }} | ||
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} | ||
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- | ||
|
||
- name: Install dependencies | ||
run: | | ||
install.packages("remotes") | ||
remotes::install_deps(dependencies = TRUE) | ||
remotes::install_dev("pkgdown") | ||
shell: Rscript {0} | ||
|
||
- name: Install package | ||
run: R CMD INSTALL . | ||
|
||
- name: Deploy package | ||
run: pkgdown::deploy_to_branch(new_process = FALSE) | ||
shell: Rscript {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ vignettes/*.md | |
.Rprofile | ||
# Local files | ||
/local/ | ||
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
--- | ||
title: "**tmap** benchmark" | ||
author: "Martijn Tennekes" | ||
date: "2020-06-20" | ||
output: html_document | ||
--- | ||
|
||
```{r setup, include=FALSE} | ||
knitr::opts_chunk$set(echo = TRUE) | ||
library(tmap) | ||
library(readxl) | ||
library(grid) | ||
library(dplyr) | ||
library(sf) | ||
library(ggplot2) | ||
library(microbenchmark) | ||
``` | ||
|
||
## Large choroplth | ||
|
||
```{r preprocess-poly,cache=TRUE,include = FALSE} | ||
# function to obtain Food Environment Atlas data (2014) | ||
get_food_envir_data <- function() { | ||
dir <- tempdir() | ||
if (!file.exists(file.path(dir, "DataDownload.xls"))) { | ||
download.file("https://www.ers.usda.gov/webdocs/DataFiles/48731/February2014.xls?v=41688", destfile = file.path(dir, "DataDownload.xls"), mode = "wb") | ||
} | ||
res <- tryCatch({ | ||
read_excel(file.path(dir, "DataDownload.xls"), sheet = "HEALTH") | ||
}, error = function(e) { | ||
stop("The excel file cannot be read. Please open it, and remove all sheets except HEALTH. The location of the file is: ", normalizePath(file.path(dir, "DataDownload.xls"))) | ||
}) | ||
} | ||
# function to obtain US county shape | ||
get_US_county_2010_shape <- function() { | ||
dir <- tempdir() | ||
download.file("http://www2.census.gov/geo/tiger/GENZ2010/gz_2010_us_050_00_20m.zip", destfile = file.path(dir, "gz_2010_us_050_00_20m.zip")) | ||
unzip(file.path(dir, "gz_2010_us_050_00_20m.zip"), exdir = dir) | ||
US <- sf::read_sf(file.path(dir, "gz_2010_us_050_00_20m.shp")) | ||
levels(US$NAME) <- iconv(levels(US$NAME), from = "latin1", to = "utf8") | ||
US | ||
} | ||
# obtain Food Environment Atlas data | ||
FEA <- get_food_envir_data() | ||
# obtain US county shape | ||
US <- get_US_county_2010_shape() | ||
US$FIPS <- paste0(US$STATE, US$COUNTY) | ||
# append data to shape | ||
#US <- append_data(US, FEA, key.shp = "FIPS", key.data = "FIPS", ignore.duplicates = TRUE) | ||
US <- left_join(US, FEA, by = c("FIPS", "FIPS")) | ||
US_cont <- US %>% | ||
subset(!STATE %in% c("02", "15", "72")) | ||
``` | ||
|
||
|
||
|
||
```{r} | ||
poly_tmap = function() { | ||
print(tm_shape(US_cont) + tm_polygons("PCT_OBESE_ADULTS10")) | ||
} | ||
poly_sf = function() { | ||
plot(US_cont[, "PCT_OBESE_ADULTS10"]) | ||
} | ||
poly_ggplot2 = function() { | ||
print(ggplot(data = US_cont, aes(fill = PCT_OBESE_ADULTS10)) + geom_sf()) | ||
} | ||
``` | ||
|
||
|
||
```{r fig.cap="tmap choropleth"} | ||
poly_tmap() | ||
``` | ||
|
||
**sf** | ||
|
||
```{r fig.cap="sf choropleth"} | ||
poly_sf() | ||
``` | ||
|
||
**ggplot2** | ||
|
||
```{r fig.cap="ggplot2 choropleth"} | ||
poly_ggplot2() | ||
``` | ||
|
||
|
||
```{r fig.cap="Benchmark results",echo=FALSE} | ||
write2png = function(e) { | ||
tmp = tempfile(fileext = ".png") | ||
png(tmp, width = 2000, height = 2000) | ||
e | ||
dev.off() | ||
} | ||
autoplot(microbenchmark(list = alist( | ||
tmap = write2png(poly_tmap()), | ||
sf = write2png(poly_sf()), | ||
ggplot2 = write2png(poly_ggplot2())), | ||
times = 3)) | ||
``` | ||
|
||
# Large dot map | ||
|
||
```{r preprocess-poly,cache=TRUE,include = FALSE} | ||
denuncia_v = read.csv("https://github.com/hbermeo/datos_espaciales/raw/master/denuncia_vial.csv", encoding = "UTF-8") | ||
denuncias = st_as_sf(denuncia_v, coords = c("long", "lat"), crs = 4326) | ||
``` | ||
|
||
|
||
|
||
```{r} | ||
dot_tmap = function() { | ||
print(tm_shape(denuncias) + tm_dots("genero", size = .1)) | ||
} | ||
dot_ggplot2 = function() { | ||
ggplot(data= denuncias, aes(color = genero)) + geom_sf() | ||
} | ||
dot_sf = function() { | ||
plot(denuncias[, "genero"]) | ||
} | ||
``` |