Last updated: 2022-05-20

Checks: 7 0

Knit directory: myTidyTuesday/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210907) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 2278db5. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/.Rhistory
    Ignored:    data/CNHI_Excel_Chart.xlsx
    Ignored:    data/Chicago.rds
    Ignored:    data/CommunityTreemap.jpeg
    Ignored:    data/Community_Roles.jpeg
    Ignored:    data/SeriesReport-20220414171148_6c3b18.xlsx
    Ignored:    data/Weekly_Chicago_IL_Regular_Reformulated_Retail_Gasoline_Prices.csv
    Ignored:    data/YammerDigitalDataScienceMembership.xlsx
    Ignored:    data/YammerMemberPage.rds
    Ignored:    data/YammerMembers.rds
    Ignored:    data/df.rds
    Ignored:    data/grainstocks.rds
    Ignored:    data/hike_data.rds
    Ignored:    data/mfg_shap.rds
    Ignored:    data/netflixTitles2.rds
    Ignored:    data/raw_weather.RData
    Ignored:    data/sample_submission.csv
    Ignored:    data/shap_int.rds
    Ignored:    data/test.csv
    Ignored:    data/train.csv
    Ignored:    data/us_states.rds
    Ignored:    data/us_states_hexgrid.geojson
    Ignored:    data/weatherstats_toronto_daily.csv
    Ignored:    data/xgboost_fit.rds
    Ignored:    data/xgboost_fit_full.rds

Untracked files:
    Untracked:  analysis/2022_May_tabular_playground.Rmd
    Untracked:  code/YammerReach.R
    Untracked:  code/chicago.R
    Untracked:  code/googleCompute.R
    Untracked:  code/work list batch targets.R
    Untracked:  environment.yml
    Untracked:  report.html

Unstaged changes:
    Deleted:    analysis/2022_02_11_tabular_playground.Rmd
    Deleted:    analysis/2022_04_18.qmd
    Modified:   code/_common.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/2022_05_20.Rmd) and HTML (docs/2022_05_20.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 2278db5 opus1993 2022-05-20 Belgium map

This is a Friday diversion, to work through Milos Popovic’s code and craft a nice looking topographic map of Belgium.

Reference https://github.com/milos-agathon/crisp-topographical-map-with-r

I'm excited to share my new topographic map of Italy🇮🇹 as well as the link to my new tutorial that shows you how to make your own crisp topo maps of any country in the world!

💡https://t.co/Weo0NcwpBX#tutorial #RStats #DataScience #dataviz #maps #coding pic.twitter.com/QTzYBjmMUJ

— Milos Popovic (@milos_agathon) May 14, 2022

First, let’s load the packages:

suppressPackageStartupMessages({
  library(elevatr)
  library(terra)
  library(tidyverse)
  library(sf)
  library(giscoR)
  library(marmap)
})

Second, let’s load the data and a helper function to glue the counts of countries onto the country labels:

#---------

crsLONGLAT <- "+proj=longlat +datum=WGS84 +no_defs"

get_sf <- function(country_sf, country_transformed) {
  country_sf <- giscoR::gisco_get_countries(
    year = "2016",
    epsg = "4326",
    resolution = "10",
    country = "Belgium"
  )

  country_transformed <- st_transform(country_sf, crs = crsLONGLAT)

  return(country_transformed)
}

country_transformed <- get_sf()
get_elevation_data <- function(country_elevation, country_elevation_df) {
  country_elevation <- get_elev_raster(
    locations = country_transformed,
    z = 10, # Please decrease the z value if you experience R crashing
    clip = "locations"
  )

  country_elevation_df <- as.data.frame(country_elevation, xy = T) %>%
    na.omit()

  colnames(country_elevation_df)[3] <- "elevation"

  return(country_elevation_df)
}

country_elevation_df <- get_elevation_data()
Mosaicing & Projecting
Clipping DEM to locations
Note: Elevation units are in meters.
get_elevation_map <- function(country_map) {
  country_map <- ggplot() +
    geom_tile(
      data = country_elevation_df,
      aes(x = x, y = y, fill = elevation)
    ) +
    scale_fill_etopo() +
    coord_sf(crs = crsLONGLAT) +
    theme_minimal() +
    theme(
      text = element_text(family = "georg", color = "#22211d"),
      axis.line = element_blank(),
      axis.text.x = element_blank(),
      axis.text.y = element_blank(),
      axis.ticks = element_blank(),
      axis.title.x = element_blank(),
      axis.title.y = element_blank(),
      legend.position = "none",
      panel.grid.major = element_line(color = "white", size = 0.2),
      panel.grid.minor = element_blank(),
      plot.title = element_text(size = 18, color = "grey20", hjust = 1, vjust = -5),
      plot.caption = element_text(size = 8, color = "grey70", hjust = .15, vjust = 20),
      plot.margin = unit(c(t = 0, r = 0, b = 0, l = 0), "lines"),
      plot.background = element_rect(fill = "white", color = NA),
      panel.background = element_rect(fill = "white", color = NA),
      panel.border = element_blank()
    ) +
    labs(
      x = "",
      y = NULL,
      title = "Topographic map of Belgium",
      subtitle = "",
      caption = "©2022 @jim_gruman"
    )

  return(country_map)
}

country_map <- get_elevation_map()

country_map


sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] marmap_1.0.6    giscoR_0.3.1    sf_1.0-7        forcats_0.5.1  
 [5] stringr_1.4.0   dplyr_1.0.9     purrr_0.3.4     readr_2.1.2    
 [9] tidyr_1.2.0     tibble_3.1.7    ggplot2_3.3.6   tidyverse_1.3.1
[13] terra_1.5-21    elevatr_0.4.2   workflowr_1.7.0

loaded via a namespace (and not attached):
  [1] colorspace_2.0-3    ellipsis_0.3.2      class_7.3-20       
  [4] rgdal_1.5-32        rprojroot_2.0.3     fs_1.5.2           
  [7] rstudioapi_0.13     proxy_0.4-26        farver_2.1.0       
 [10] bit64_4.0.5         fansi_1.0.3         lubridate_1.8.0    
 [13] xml2_1.3.3          codetools_0.2-18    R.methodsS3_1.8.1  
 [16] ncdf4_1.19          cachem_1.0.6        knitr_1.39         
 [19] jsonlite_1.8.0      broom_0.8.0         dbplyr_2.1.1       
 [22] R.oo_1.24.0         compiler_4.1.3      httr_1.4.3         
 [25] backports_1.4.1     assertthat_0.2.1    fastmap_1.1.0      
 [28] cli_3.2.0           later_1.3.0         s2_1.0.7           
 [31] prettyunits_1.1.1   htmltools_0.5.2     tools_4.1.3        
 [34] gtable_0.3.0        glue_1.6.2          reshape2_1.4.4     
 [37] wk_0.6.0            rappdirs_0.3.3      Rcpp_1.0.8.3       
 [40] cellranger_1.1.0    jquerylib_0.1.4     styler_1.7.0       
 [43] raster_3.5-15       vctrs_0.4.1         countrycode_1.4.0  
 [46] progressr_0.10.0    xfun_0.31           ps_1.7.0           
 [49] rvest_1.0.2         lifecycle_1.0.1     getPass_0.2-2      
 [52] scales_1.2.0        hms_1.1.1           promises_1.2.0.1   
 [55] slippymath_0.3.1    rematch2_2.1.2      yaml_2.3.5         
 [58] curl_4.3.2          memoise_2.0.1       sass_0.4.1         
 [61] tweetrmd_0.0.9      stringi_1.7.6       RSQLite_2.2.14     
 [64] highr_0.9           e1071_1.7-9         shape_1.4.6        
 [67] rlang_1.0.2         pkgconfig_2.0.3     evaluate_0.15      
 [70] lattice_0.20-45     bit_4.0.4           processx_3.5.3     
 [73] tidyselect_1.1.2    plyr_1.8.7          magrittr_2.0.3     
 [76] geojsonsf_2.0.2     R6_2.5.1            generics_0.1.2     
 [79] DBI_1.1.2           pillar_1.7.0        haven_2.5.0        
 [82] whisker_0.4         withr_2.5.0         units_0.8-0        
 [85] sp_1.4-7            modelr_0.1.8        crayon_1.5.1       
 [88] KernSmooth_2.23-20  utf8_1.2.2          tzdb_0.3.0         
 [91] rmarkdown_2.14      progress_1.2.2      grid_4.1.3         
 [94] readxl_1.4.0        blob_1.2.3          callr_3.7.0        
 [97] git2r_0.30.1        reprex_2.0.1        digest_0.6.29      
[100] classInt_0.4-3      adehabitatMA_0.3.14 R.cache_0.15.0     
[103] httpuv_1.6.5        R.utils_2.11.0      munsell_0.5.0      
[106] bslib_0.3.1        
LS0tDQp0aXRsZTogIkNyZWF0ZSBhIENyaXNwIFRvcG9ncmFwaGljIE1hcCBpbiBSIg0KYXV0aG9yOiAiSmltIEdydW1hbiINCmRhdGU6ICJNYXkgMjAsIDIwMjIiDQpvdXRwdXQ6DQogIHdvcmtmbG93cjo6d2Zsb3dfaHRtbDoNCiAgICB0b2M6IG5vDQogICAgY29kZV9mb2xkaW5nOiBoaWRlDQogICAgY29kZV9kb3dubG9hZDogdHJ1ZQ0KICAgIGRmX3ByaW50OiBwYWdlZA0KZWRpdG9yX29wdGlvbnM6DQogIGNodW5rX291dHB1dF90eXBlOiBjb25zb2xlDQotLS0NCg0KVGhpcyBpcyBhIEZyaWRheSBkaXZlcnNpb24sIHRvIHdvcmsgdGhyb3VnaCBNaWxvcyBQb3BvdmljJ3MgY29kZSBhbmQgY3JhZnQgYSBuaWNlIGxvb2tpbmcgdG9wb2dyYXBoaWMgbWFwIG9mIEJlbGdpdW0uDQoNCmBgYHtyIHNldHVwLCBpbmNsdWRlID0gRkFMU0V9DQoNCmtuaXRyOjpvcHRzX2NodW5rJHNldCgNCiAgZmlnLndpZHRoID0gMTIsIGNhY2hlID0gRkFMU0UsIHdhcm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