Closed Robinlovelace closed 5 years ago
Precipitation trend map
http://localhost:28604/session/viewhtml407c6d97226d/index.html
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"))
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)
Great work! Challenge: see if you can reproduce the exact result I got and then do it using sf::read_sf()
not rgdal::readOGR()
.
Entries for best map