geocompx / geocompr

Geocomputation with R: an open source book
https://r.geocompx.org/
Other
1.58k stars 584 forks source link

Best map competition EGU #371

Closed Robinlovelace closed 5 years ago

Robinlovelace commented 5 years ago

Entries for best map

luigicesarini commented 5 years ago

Precipitation trend map

http://localhost:28604/session/viewhtml407c6d97226d/index.html

luigicesarini commented 5 years ago

Trend Map

luigicesarini commented 5 years ago

egu_dd <- readOGR(dsn = ".",layer = "example_egu") colnames(egu_dd@data) <- c("Station","Duration","Corrected Zc","new P-value","N/N*","Original Z","old P.value","Tau","Sen.s.slop", "old.variance","new.variance","Abs.Sen","lat","lon","elevation","region","a_2","n_2","a_5","n_5", "a_10","n_10","a_20","n_20","a_50","n_50","a_100","n_100","a_200","n_200","a_500","n_500", "intensity_2","intensity_5","intensity_10","intensity_20","intensity_50","intensity_100","intensity_200","intensity_500")

tmap_mode("view") tm_basemap(leaflet::providers$Esri.WorldImagery,alpha = 0.95)+ tm_shape(egu_dd) + tm_symbols(col="Sen.s.slop",size = "Abs.Sen",scale = 2, palette=c("red4","brown1","navy","lightskyblue1"),perceptual = FALSE,border.col = "white", popup.vars = c("elevation", "Sen.s.slop", "new P-value"))+ tm_layout(title = "Trend on precipitation historical data")+ tm_legend(legend.only=FALSE,legend.show= FALSE,legend.outside=TRUE)+ tm_view(view.legend.position = c("right","bottom"))

example_egu.zip

Robinlovelace commented 5 years ago

Many thanks for the reproducible example @luigicesarini, you win a physical copy of the book! A resource that may be useful if you'd like to show reproducible code is this explanation of the reprex function in the reprex package: https://github.com/tidyverse/reprex

I used reprex() to test the reproducibility of your code:

# reprex example
library(rgdal)
#> Loading required package: sp
#> rgdal: version: 1.3-9, (SVN revision 794)
#>  Geospatial Data Abstraction Library extensions to R successfully loaded
#>  Loaded GDAL runtime: GDAL 2.1.2, released 2016/10/24
#>  Path to GDAL shared files: /usr/share/gdal/2.1
#>  GDAL binary built with GEOS: TRUE 
#>  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
#>  Path to PROJ.4 shared files: (autodetected)
#>  Linking to sp version: 1.3-1
library(tmap)
u = "https://github.com/Robinlovelace/geocompr/files/3063017/example_egu.zip"
download.file(u, "example_egu.zip")
unzip("example_egu.zip")
egu_dd <- readOGR(dsn = ".",layer = "example_egu")
#> OGR data source with driver: ESRI Shapefile 
#> Source: "/tmp/RtmpPppZow/reprex4a001fffdb20", layer: "example_egu"
#> with 161 features
#> It has 40 fields
colnames(egu_dd@data) <- c("Station","Duration","Corrected Zc","new P-value","N/N*","Original Z","old P.value","Tau","Sen.s.slop", "old.variance","new.variance","Abs.Sen","lat","lon","elevation","region","a_2","n_2","a_5","n_5", "a_10","n_10","a_20","n_20","a_50","n_50","a_100","n_100","a_200","n_200","a_500","n_500", "intensity_2","intensity_5","intensity_10","intensity_20","intensity_50","intensity_100","intensity_200","intensity_500")

# tmap_mode("view")
tm_basemap(leaflet::providers$Esri.WorldImagery,alpha = 0.95)+
tm_shape(egu_dd) +
tm_symbols(col="Sen.s.slop",size = "Abs.Sen",scale = 2,
palette=c("red4","brown1","navy","lightskyblue1"),perceptual = FALSE,border.col = "white",
popup.vars = c("elevation", "Sen.s.slop", "new P-value"))+
tm_layout(title = "Trend on precipitation historical data")+
tm_legend(legend.only=FALSE,legend.show= FALSE,legend.outside=TRUE)+
tm_view(view.legend.position = c("right","bottom"))
#> Linking to GEOS 3.5.1, GDAL 2.1.2, PROJ 4.9.3

Created on 2019-04-10 by the reprex package (v0.2.1)

Session info ``` r devtools::session_info() #> ─ Session info ────────────────────────────────────────────────────────── #> setting value #> version R version 3.5.2 (2018-12-20) #> os Debian GNU/Linux 9 (stretch) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Etc/UTC #> date 2019-04-10 #> #> ─ Packages ────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.0 2017-04-11 [1] CRAN (R 3.5.2) #> backports 1.1.3 2018-12-14 [1] CRAN (R 3.5.2) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.5.2) #> callr 3.1.1 2018-12-21 [1] CRAN (R 3.5.2) #> class 7.3-15 2019-01-01 [1] CRAN (R 3.5.2) #> classInt 0.3-1 2018-12-18 [1] CRAN (R 3.5.2) #> cli 1.0.1 2018-09-25 [1] CRAN (R 3.5.2) #> codetools 0.2-16 2018-12-24 [1] CRAN (R 3.5.2) #> colorspace 1.4-0 2019-01-13 [1] CRAN (R 3.5.2) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.5.2) #> crosstalk 1.0.0 2016-12-21 [1] CRAN (R 3.5.2) #> curl 3.3 2019-01-10 [1] CRAN (R 3.5.2) #> DBI 1.0.0 2018-05-02 [1] CRAN (R 3.5.2) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.5.2) #> devtools 2.0.1 2018-10-26 [1] CRAN (R 3.5.2) #> dichromat 2.0-0 2013-01-24 [1] CRAN (R 3.5.2) #> digest 0.6.18 2018-10-10 [1] CRAN (R 3.5.2) #> e1071 1.7-0.1 2019-01-21 [1] CRAN (R 3.5.2) #> evaluate 0.13 2019-02-12 [1] CRAN (R 3.5.2) #> fs 1.2.6 2018-08-23 [1] CRAN (R 3.5.2) #> glue 1.3.0 2018-07-17 [1] CRAN (R 3.5.2) #> highr 0.7 2018-06-09 [1] CRAN (R 3.5.2) #> htmltools 0.3.6 2017-04-28 [1] CRAN (R 3.5.2) #> htmlwidgets 1.3 2018-09-30 [1] CRAN (R 3.5.2) #> httpuv 1.4.5.1 2018-12-18 [1] CRAN (R 3.5.2) #> httr 1.4.0 2018-12-11 [1] CRAN (R 3.5.2) #> KernSmooth 2.23-15 2015-06-29 [2] CRAN (R 3.5.2) #> knitr 1.22 2019-03-08 [1] CRAN (R 3.5.2) #> later 0.8.0 2019-02-11 [1] CRAN (R 3.5.2) #> lattice 0.20-38 2018-11-04 [2] CRAN (R 3.5.2) #> leaflet 2.0.2 2018-08-27 [1] CRAN (R 3.5.2) #> lwgeom 0.1-6 2019-03-20 [1] Github (r-spatial/lwgeom@b11624d) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.5.2) #> mapview 2.6.3 2018-12-19 [1] CRAN (R 3.5.2) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.5.2) #> mime 0.6 2018-10-05 [1] CRAN (R 3.5.2) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.5.2) #> pkgbuild 1.0.2 2018-10-16 [1] CRAN (R 3.5.2) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.5.2) #> png 0.1-7 2013-12-03 [1] CRAN (R 3.5.2) #> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.5.2) #> processx 3.3.0 2019-03-10 [1] CRAN (R 3.5.2) #> promises 1.0.1 2018-04-13 [1] CRAN (R 3.5.2) #> ps 1.3.0 2018-12-21 [1] CRAN (R 3.5.2) #> R6 2.4.0 2019-02-14 [1] CRAN (R 3.5.2) #> raster 2.9-1 2019-02-26 [1] Github (rspatial/raster@9d05c09) #> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.5.2) #> Rcpp 1.0.0 2018-11-07 [1] CRAN (R 3.5.2) #> remotes 2.0.2 2018-10-30 [1] CRAN (R 3.5.2) #> rgdal * 1.3-9 2019-02-21 [1] CRAN (R 3.5.2) #> rgeos 0.4-2 2018-11-08 [1] CRAN (R 3.5.2) #> rlang 0.3.1 2019-01-08 [1] CRAN (R 3.5.2) #> rmarkdown 1.11 2018-12-08 [1] CRAN (R 3.5.2) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.5.2) #> satellite 1.0.1 2017-10-18 [1] CRAN (R 3.5.2) #> scales 1.0.0 2018-08-09 [1] CRAN (R 3.5.2) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.2) #> sf * 0.7-2 2018-12-20 [1] CRAN (R 3.5.2) #> shiny 1.2.0 2018-11-02 [1] CRAN (R 3.5.2) #> sp * 1.3-1 2018-06-05 [1] CRAN (R 3.5.2) #> stringi 1.3.1 2019-02-13 [1] CRAN (R 3.5.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.2) #> testthat 2.0.1 2018-10-13 [1] CRAN (R 3.5.2) #> tmap * 2.2 2019-01-05 [1] CRAN (R 3.5.2) #> tmaptools 2.0-1 2018-08-07 [1] CRAN (R 3.5.2) #> units 0.6-2 2018-12-05 [1] CRAN (R 3.5.2) #> usethis 1.4.0 2018-08-14 [1] CRAN (R 3.5.2) #> viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.5.2) #> webshot 0.5.1 2018-09-28 [1] CRAN (R 3.5.2) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.5.2) #> xfun 0.5 2019-02-20 [1] CRAN (R 3.5.2) #> XML 3.98-1.19 2019-03-06 [1] CRAN (R 3.5.2) #> xml2 1.2.0 2018-01-24 [1] CRAN (R 3.5.2) #> xtable 1.8-3 2018-08-29 [1] CRAN (R 3.5.2) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.5.2) #> #> [1] /usr/local/lib/R/site-library #> [2] /usr/local/lib/R/library ```

Great work! Challenge: see if you can reproduce the exact result I got and then do it using sf::read_sf() not rgdal::readOGR().