layout: true background-image: url(img/course-logo.png), url(img/logo_SBR.png), url(img//NTU-Logo-full-colour.png) background-position: right top 30px, right 50px bottom 50px,left 50px bottom 50px, top 350px left 500px background-size: 45%, 25%, 20% # Fundamental of Data Science for EESS --- <br> <br> <br> <br> ## R session 06 - Data mapping .font120[**Daniel Vaulot**] 2021-02-24 --- layout: false class: middle, inverse # Outline .font150[ * Simple features * Static maps * Plotting your data * Interactive map ] --- exclude: true ## Resources used * Simple maps : https://www.r-spatial.org/r/2018/10/25/ggplot2-sf.html ## Other resources * Global maps : https://github.com/e-cavan/spatial_mapping_R * Ocean maps: https://www.researchgate.net/profile/Robert_Bauer9/publication/315494507_oceanmap_Mapping_oceanographic_data/links/58d2987292851cd76d346f65/oceanmap-Mapping-oceanographic-data.pdf --- layout: false # Installation and Resources .pull-left[ ## Packages ### New * sf * rnaturalearth * rnaturalearthdata * leaflet ### Previously used * ggplot2 * stringr * dplyr ] .pull-right[ <img src="img/R-geocomputation.png" width="30%" style="display: block; margin: auto;" /> #### Reading list * [Geocomputation with R - Chapter 2](https://geocompr.robinlovelace.net/spatial-class.html) * [Geocomputation with R - Chapter 8](https://geocompr.robinlovelace.net/adv-map.html) #### Other resources * [Spatial data science](https://keen-swartz-3146c4.netlify.com/index.html) * [Modern geospatial analysis with R](http://files.zevross.com/workshops/spatial/slides/html/0-deck-list.html) ] --- # What we want to do... <img src="img/map-example-swiss.png" width="70%" style="display: block; margin: auto;" /> --- layout: true # Simple Features (sf) --- <img src="img/sf.jpg" width="60%" style="display: block; margin: auto;" /> * https://github.com/r-spatial/sf --- * Simple features is an open standard developed and endorsed by the Open Geospatial Consortium (OGC). * Simple features is a hierarchical data model that represents a wide range of geometry types. <img src="img/sf-classes.png" width="40%" style="display: block; margin: auto;" /> --- * A **point** is simply a coordinate in 2D (can be also 3D or 4D space) * POINT (5 2) * A **linestring** is a sequence of points with a straight line connecting the points * LINESTRING (1 5, 4 4, 4 1, 2 2, 3 2) * A **polygon** is a sequence of points that form a closed, non-intersecting ring. * POLYGON (1 5, 2 2, 4 1, 4 4, 1 5) <img src="img/sf-classes-01.png" width="60%" style="display: block; margin: auto;" /> --- * MULTIPOINT (5 2, 1 3, 3 4, 3 2) * MULTILINESTRING ((1 5, 4 4, 4 1, 2 2, 3 2), (1 2, 2 4)) * MULTIPOLYGON (((1 5, 2 2, 4 1, 4 4, 1 5), (0 2, 1 2, 1 3, 0 3, 0 2))) <img src="img/sf-classes-02.png" width="60%" style="display: block; margin: auto;" /> --- * A **geometry collection** can contain any combination of geometries including (multi)points and linestrings * GEOMETRYCOLLECTION (MULTIPOINT (5 2, 1 3, 3 4, 3 2), LINESTRING (1 5, 4 4, 4 1, 2 2, 3 2)) <img src="img/sf-geomcollection.png" width="40%" style="display: block; margin: auto;" /> --- * Simple feature objects in R are stored in a data frame * Geographic data occupying a special column, usually named `geom` or `geometry`. <img src="img/sf-examples.png" width="60%" style="display: block; margin: auto;" /> Three classes of sf objects * **sfg** : geometry * **sfc** : column - set of geometry plus coordinates system * **sf** : information about each geometry --- ## sf geometry (sfg) class ```r library(sf) ``` ``` Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1 ``` -- * Creating a point from a vector ```r sf::st_point(c(5, 2)) ``` ``` POINT (5 2) ``` -- * For line, we need to create a **matrix** with rbind ```r multipoint_matrix = rbind(c(5, 2), c(1, 3), c(3, 4), c(3, 2)) st_multipoint(multipoint_matrix) ``` ``` MULTIPOINT ((5 2), (1 3), (3 4), (3 2)) ``` --- ## sf geometry (sfg) class * For multiline, we need to create a **list of matrices** ```r multilinestring_list = list(rbind(c(1, 5), c(4, 4), c(4, 1), c(2, 2), c(3, 2)), rbind(c(1, 2), c(2, 4))) st_multilinestring((multilinestring_list)) ``` ``` MULTILINESTRING ((1 5, 4 4, 4 1, 2 2, 3 2), (1 2, 2 4)) ``` -- * Idem for geometry collection ```r geometrycollection_list = list(sf::st_multipoint(multipoint_matrix), sf::st_multilinestring(multilinestring_list)) st_geometrycollection(geometrycollection_list) ``` ``` GEOMETRYCOLLECTION (MULTIPOINT ((5 2), (1 3), (3 4), (3 2)), MULTILINESTRING ((1 5, 4 4, 4 1, 2 2, 3 2), (1 2, 2 4))) ``` --- ## sf column (sfc) class List of sfg obkects that also contains also information about the coordinate system ```r point1 = st_point(c(5, 2)) point2 = st_point(c(1, 3)) points_sfc = st_sfc(point1, point2) points_sfc ``` ``` Geometry set for 2 features geometry type: POINT dimension: XY bbox: xmin: 1 ymin: 2 xmax: 5 ymax: 3 CRS: NA ``` ``` POINT (5 2) ``` ``` POINT (1 3) ``` --- ## sf column (sfc) class Now add Coordinate Reference System (crs) ```r st_sfc(point1, point2, crs = 4326) ``` ``` Geometry set for 2 features geometry type: POINT dimension: XY bbox: xmin: 1 ymin: 2 xmax: 5 ymax: 3 geographic CRS: WGS 84 ``` ``` POINT (5 2) ``` ``` POINT (1 3) ``` --- ## sf class Add some information about the geometry. ```r lnd_point = st_point(c(0.1, 51.5)) # sfg object lnd_geom = st_sfc(lnd_point, crs = 4326) # sfc object lnd_attrib = data.frame( # data.frame object name = "London", temperature = 25, date = as.Date("2017-06-21") ) st_sf(lnd_attrib, geometry = lnd_geom) ``` ``` Simple feature collection with 1 feature and 3 fields geometry type: POINT dimension: XY bbox: xmin: 0.1 ymin: 51.5 xmax: 0.1 ymax: 51.5 geographic CRS: WGS 84 name temperature date geometry 1 London 25 2017-06-21 POINT (0.1 51.5) ``` --- layout: true # Static maps --- ## Load necessary libraries ```r library("readxl") # Import the data from Excel file library("dplyr") # filter and reformat data frames library("ggplot2") # graphics library("sf") # simple features library("rnaturalearth") library("rnaturalearthdata") ``` --- ## Read the world map data * `scale` can be 'small', 'medium', 'large' * `returnclass` can be 'sp' or 'sf' - sf (simple features) is an evolution of sp ```r world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf") ``` --- The world data are returned as a sf (simple feature) dataframe which contains * normal fields * one field called geometry which contains points, lines or polygon coordinate information ```r colnames(world) ``` ``` [1] "scalerank" "featurecla" "labelrank" "sovereignt" "sov_a3" [6] "adm0_dif" "level" "type" "admin" "adm0_a3" [11] "geou_dif" "geounit" "gu_a3" "su_dif" "subunit" [16] "su_a3" "brk_diff" "name" "name_long" "brk_a3" [21] "brk_name" "brk_group" "abbrev" "postal" "formal_en" [26] "formal_fr" "note_adm0" "note_brk" "name_sort" "name_alt" [31] "mapcolor7" "mapcolor8" "mapcolor9" "mapcolor13" "pop_est" [36] "gdp_md_est" "pop_year" "lastcensus" "gdp_year" "economy" [41] "income_grp" "wikipedia" "fips_10" "iso_a2" "iso_a3" [46] "iso_n3" "un_a3" "wb_a2" "wb_a3" "woe_id" [51] "adm0_a3_is" "adm0_a3_us" "adm0_a3_un" "adm0_a3_wb" "continent" [56] "region_un" "subregion" "region_wb" "name_len" "long_len" [61] "abbrev_len" "tiny" "homepart" "geometry" ``` --- * The field `name` contains the name of the countries, `continent` the continent, etc... * The field `geometry` contains the country outline <table class="table table-striped table-hover table-condensed" style="font-size: 9px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> name </th> <th style="text-align:left;"> continent </th> <th style="text-align:left;"> geometry </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Aruba </td> <td style="text-align:left;"> North America </td> <td style="text-align:left;"> MULTIPOLYGON (((-69.89912 1... </td> </tr> </tbody> </table> -- ```r world$geometry[1] ``` ``` Geometry set for 1 feature geometry type: MULTIPOLYGON dimension: XY bbox: xmin: -70.06611 ymin: 12.423 xmax: -69.8957 ymax: 12.61411 CRS: +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 ``` --- ## A simple world map .left-code[ * Use `geom_sf` ```r # Set the black and white theme theme_set(theme_bw()) ggplot(data = world) + geom_sf() ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-22-1.png" width="80%" style="display: block; margin: auto;" /> ] --- ## A simple world map .left-code[ * Use `coord_sf(expand = FALSE)`to have the axis labels ```r ggplot(data = world) + geom_sf() + coord_sf(expand = FALSE) ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-23-1.png" width="80%" style="display: block; margin: auto;" /> ] --- ## Color continents .left-code[ * Add `color="white", fill="blue"` ```r ggplot(data = world) + geom_sf(color="white", fill="blue")+ coord_sf(expand = FALSE) ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-24-1.png" width="80%" style="display: block; margin: auto;" /> ] --- ## Plot population .left-code[ * Use value of column `pop_est` ```r ggplot(data = world) + geom_sf(aes(fill= pop_est))+ coord_sf(expand = FALSE) ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-25-1.png" width="80%" style="display: block; margin: auto;" /> ] --- ## Plot population .left-code[ * Change color scale * Transform the data ```r ggplot(data = world) + geom_sf(aes(fill= pop_est)) + coord_sf(expand = FALSE) + scale_fill_viridis_c(trans = "log10") ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-26-1.png" width="80%" style="display: block; margin: auto;" /> ] --- ## Modify projections .left-code[ * Specify coordinate system: https://geocompr.robinlovelace.net/spatial-class.html#crs-intro * Lambert projection * From the North Pole * "+proj=laea +lat_0=90 +lon_0=0 " ```r ggplot(data = world) + geom_sf() + coord_sf(expand = FALSE, crs = "+proj=laea +lat_0=90 +lon_0=0 ") ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-27-1.png" width="70%" style="display: block; margin: auto;" /> ] --- ## Zoom .left-code[ * Centered on Singapore ```r ggplot(data = world) + geom_sf() + coord_sf(xlim=c(90,110), ylim=c(-10,10)) ``` .warning[Resolution is not optimal] ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-28-1.png" width="70%" style="display: block; margin: auto;" /> ] --- ## Add country names * Must first define coordinates centroid of each country (X and Y) ```r world_centroids<- st_coordinates(st_centroid(world$geometry)) ``` -- * Bind the 2 tables ```r world_centroids <- cbind(world, world_centroids) ``` <table class="table table-striped table-hover table-condensed" style="font-size: 9px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> name </th> <th style="text-align:right;"> X </th> <th style="text-align:right;"> Y </th> <th style="text-align:left;"> geometry </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Aruba </td> <td style="text-align:right;"> -69.98268 </td> <td style="text-align:right;"> 12.52088 </td> <td style="text-align:left;"> MULTIPOLYGON (((-69.89912 1... </td> </tr> </tbody> </table> --- ## Add country names .left-code[ * Use `geom_text()` ```r ggplot(data = world_centroids) + geom_sf() + coord_sf(xlim=c(70,130), ylim=c(-20,20)) + geom_text(aes(x = X, y=Y, label=name), size=5) + xlab("Longitude") + ylab("Latitude") ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-32-1.png" width="80%" style="display: block; margin: auto;" /> ] --- layout: true # Plot data --- ## Read the data ```r bolido <- readxl::read_excel("data/bolido.xlsx") ``` <table class="table table-striped table-hover table-condensed" style="font-size: 9px; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:left;"> cruise </th> <th style="text-align:left;"> station_id </th> <th style="text-align:left;"> date </th> <th style="text-align:left;"> depth_level </th> <th style="text-align:right;"> depth </th> <th style="text-align:right;"> latitude </th> <th style="text-align:right;"> longitude </th> <th style="text-align:left;"> oceanic_region </th> <th style="text-align:right;"> temperature </th> <th style="text-align:right;"> salinity </th> <th style="text-align:right;"> reads_total </th> <th style="text-align:right;"> bolido_reads </th> <th style="text-align:right;"> bolido_pct </th> <th style="text-align:left;"> species_dominant </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> MALINA </td> <td style="text-align:left;"> 430 </td> <td style="text-align:left;"> 2009-08-18 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 71.1300 </td> <td style="text-align:right;"> -136.420 </td> <td style="text-align:left;"> Beaufort Sea </td> <td style="text-align:right;"> -0.804 </td> <td style="text-align:right;"> 25.935 </td> <td style="text-align:right;"> 10495 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 0.0381134 </td> <td style="text-align:left;"> Parmales_env_3B_sp. </td> </tr> <tr> <td style="text-align:left;"> MALINA </td> <td style="text-align:left;"> 460 </td> <td style="text-align:left;"> 2009-08-19 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 70.4000 </td> <td style="text-align:right;"> -136.030 </td> <td style="text-align:left;"> Beaufort Sea </td> <td style="text-align:right;"> 0.076 </td> <td style="text-align:right;"> 25.384 </td> <td style="text-align:right;"> 9591 </td> <td style="text-align:right;"> 4 </td> <td style="text-align:right;"> 0.0417058 </td> <td style="text-align:left;"> Parmales_env_3B_sp. </td> </tr> <tr> <td style="text-align:left;"> MALINA </td> <td style="text-align:left;"> 540 </td> <td style="text-align:left;"> 2009-08-17 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 70.4500 </td> <td style="text-align:right;"> -137.530 </td> <td style="text-align:left;"> Beaufort Sea </td> <td style="text-align:right;"> -0.610 </td> <td style="text-align:right;"> 26.246 </td> <td style="text-align:right;"> 9900 </td> <td style="text-align:right;"> 14 </td> <td style="text-align:right;"> 0.1414141 </td> <td style="text-align:left;"> Parmales_env_3B_sp. </td> </tr> <tr> <td style="text-align:left;"> MALINA </td> <td style="text-align:left;"> 620 </td> <td style="text-align:left;"> 2009-08-11 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 70.6800 </td> <td style="text-align:right;"> -139.627 </td> <td style="text-align:left;"> Beaufort Sea </td> <td style="text-align:right;"> 1.231 </td> <td style="text-align:right;"> 22.522 </td> <td style="text-align:right;"> 7557 </td> <td style="text-align:right;"> 11 </td> <td style="text-align:right;"> 0.1455604 </td> <td style="text-align:left;"> Parmales_env_3B_sp. </td> </tr> <tr> <td style="text-align:left;"> MALINA </td> <td style="text-align:left;"> 670 </td> <td style="text-align:left;"> 2009-08-10 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 69.7980 </td> <td style="text-align:right;"> -138.441 </td> <td style="text-align:left;"> Beaufort Sea </td> <td style="text-align:right;"> 3.740 </td> <td style="text-align:right;"> 23.560 </td> <td style="text-align:right;"> 8348 </td> <td style="text-align:right;"> 22 </td> <td style="text-align:right;"> 0.2635362 </td> <td style="text-align:left;"> Parmales_env_3B_sp. </td> </tr> <tr> <td style="text-align:left;"> MALINA </td> <td style="text-align:left;"> 760 </td> <td style="text-align:left;"> 2009-08-12 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 3 </td> <td style="text-align:right;"> 70.3300 </td> <td style="text-align:right;"> -140.470 </td> <td style="text-align:left;"> Beaufort Sea </td> <td style="text-align:right;"> 0.511 </td> <td style="text-align:right;"> 22.455 </td> <td style="text-align:right;"> 8319 </td> <td style="text-align:right;"> 6 </td> <td style="text-align:right;"> 0.0721241 </td> <td style="text-align:left;"> Parmales_env_3A_sp. </td> </tr> <tr> <td style="text-align:left;"> CASES </td> <td style="text-align:left;"> CA15 </td> <td style="text-align:left;"> 2003-10-01 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 29 </td> <td style="text-align:right;"> 71.5367 </td> <td style="text-align:right;"> -126.955 </td> <td style="text-align:left;"> Arctic Ocean </td> <td style="text-align:right;"> -0.780 </td> <td style="text-align:right;"> 30.620 </td> <td style="text-align:right;"> 12354 </td> <td style="text-align:right;"> 211 </td> <td style="text-align:right;"> 1.7079488 </td> <td style="text-align:left;"> Parmales_env_1_X_sp. </td> </tr> <tr> <td style="text-align:left;"> CASES </td> <td style="text-align:left;"> 200 </td> <td style="text-align:left;"> 2003-11-01 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 35 </td> <td style="text-align:right;"> 69.9290 </td> <td style="text-align:right;"> -126.489 </td> <td style="text-align:left;"> Arctic Ocean </td> <td style="text-align:right;"> -1.460 </td> <td style="text-align:right;"> 31.500 </td> <td style="text-align:right;"> 12797 </td> <td style="text-align:right;"> 544 </td> <td style="text-align:right;"> 4.2509963 </td> <td style="text-align:left;"> Parmales_env_1_X_sp. </td> </tr> <tr> <td style="text-align:left;"> ArcticNet </td> <td style="text-align:left;"> CA18 </td> <td style="text-align:left;"> 2005-09-01 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 32 </td> <td style="text-align:right;"> 70.6663 </td> <td style="text-align:right;"> -122.993 </td> <td style="text-align:left;"> Arctic Ocean </td> <td style="text-align:right;"> -1.040 </td> <td style="text-align:right;"> 32.040 </td> <td style="text-align:right;"> 9531 </td> <td style="text-align:right;"> 43 </td> <td style="text-align:right;"> 0.4511594 </td> <td style="text-align:left;"> Triparma_laevis_clade </td> </tr> <tr> <td style="text-align:left;"> CFL </td> <td style="text-align:left;"> 405 </td> <td style="text-align:left;"> 2007-11-01 </td> <td style="text-align:left;"> surface </td> <td style="text-align:right;"> 10 </td> <td style="text-align:right;"> 70.6217 </td> <td style="text-align:right;"> -123.001 </td> <td style="text-align:left;"> Arctic Ocean </td> <td style="text-align:right;"> -1.650 </td> <td style="text-align:right;"> 30.130 </td> <td style="text-align:right;"> 13471 </td> <td style="text-align:right;"> 20 </td> <td style="text-align:right;"> 0.1484671 </td> <td style="text-align:left;"> Parmales_env_1_X_sp. </td> </tr> </tbody> </table> --- ## A bit of biology... Bolidophyceae and Parmales .pull-left[ ### _Triparma_ <img src="img/2011-Ichinomya-Triparma.png" width="70%" style="display: block; margin: auto;" /> * Covered with silica ] .pull-right[ ### _Bolidomonas_ <img src="img/1999-Guillou-Bolidomonas_drawing.png" width="50%" style="display: block; margin: auto;" /> * 1.5 µm ] .footnote[_Guillou, L., Chrétiennot-Dinet, M.-J., Medlin, L.K., Claustre, H., Loiseaux-de Goër, S. & Vaulot, D. 1999. J. Phycol. 35:368–81. Ichinomiya, M., Yoshikawa, S., Kamiya, M., Ohki, K., Takaichi, S. & Kuwata, A. 2011. J. Phycol. 47:144–51. Ichinomiya, M., dos Santos, A.L., Gourvil, P., Yoshikawa, S., Kamiya, M., Ohki, K., Audic, S. et al. 2016. ISME J. 10:2419–34._ ] --- ## Plot the stations where Bolidophyceae found .left-code[ * Filter by to remove stations where Bolido are not present ```r ggplot(data = world) + geom_sf()+ coord_sf(expand = FALSE) + geom_point(data=filter(bolido, bolido_pct >0), aes(x=longitude, y=latitude), size=3) ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-37-1.png" width="90%" style="display: block; margin: auto;" /> ] --- ## Percentage of Bolidophyceae .left-code[ * Filter by to remove stations where Bolido are not present ```r ggplot(data = world) + geom_sf()+ coord_sf(expand = FALSE) + geom_point(data=filter(bolido, bolido_pct >0), aes(x=longitude, y=latitude, size=bolido_pct), color="blue") ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-38-1.png" width="90%" style="display: block; margin: auto;" /> ] --- ## Dominant species of _Triparma_ .left-code[ * Color with species * Put species legend at bottom on 2 rows ```r ggplot(data = world) + geom_sf()+ coord_sf(expand = FALSE) + geom_point(data=filter(bolido, bolido_pct >0, stringr::str_detect(species_dominant, "Triparma")), aes(x=longitude, y=latitude, color=species_dominant), size = 4) + scale_colour_viridis_d() + theme(legend.position="bottom") + guides(color=guide_legend(nrow=2, byrow=TRUE)) ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-39-1.png" width="90%" style="display: block; margin: auto;" /> ] --- layout: true # Interactive maps --- ## Leaflet .pull-left[ * Javascript: https://leafletjs.com/ * Leaflet for R : https://rstudio.github.io/leaflet/ * All functions from `leaflet` package ```r library("leaflet") ``` ] .pull-right[ <img src="img/leaflet.png" width="80%" style="display: block; margin: auto;" /> ] --- ## Create an empty map .left-code[ ```r leaflet(width = 750, height = 500) ``` ] .right-plot[
] --- ## Add background (tiles) .left-code[ ```r leaflet(width = 750, height = 500)%>% addTiles() ``` ] .right-plot[
] --- ## Set limits and zoom .left-code[ ```r leaflet(width = 750, height = 500)%>% addTiles() %>% setView(lng=0, lat=0, zoom=2) ``` ] .right-plot[
] --- ## Adding data points .left-code[ ```r leaflet(width = 750, height = 500)%>% addTiles() %>% setView(lng=0, lat=0, zoom=2) %>% addCircleMarkers(data = bolido, lat = ~ latitude, lng = ~ longitude, radius = 5, label = ~ station_id, labelOptions = labelOptions(textsize = "10px", noHide = T), clusterOptions = markerClusterOptions()) ``` ] .right-plot[
] --- ## Adding background .left-code[ ```r leaflet(width = 750, height = 500)%>% addTiles() %>% setView(lng=0, lat=0, zoom=2) %>% addCircleMarkers(data = bolido, lat = ~ latitude, lng = ~ longitude, radius = 5, label = ~ station_id, labelOptions = labelOptions(textsize = "10px", noHide = T), clusterOptions = markerClusterOptions()) %>% addProviderTiles(providers$Esri.OceanBasemap) ``` * https://leaflet-extras.github.io/leaflet-providers/preview/ ] .right-plot[
] --- layout: true # Other packages --- ## Thematic maps (tmap) * https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html <img src="img/thematic_maps_01.png" width="60%" style="display: block; margin: auto;" /> --- ## Raster * https://cran.r-project.org/web/packages/raster/vignettes/Raster.pdf <img src="img/raster_sst.png" width="60%" style="display: block; margin: auto;" /> --- layout: true # Your turn --- .left-code[ * Use four shapes files * world * world_centroids * bathymetry 0 m * bathymetry 200 m * https://www.naturalearthdata.com/downloads/10m-physical-vectors/10m-bathymetry/ * Files can be read with `sf::read_sf` ```r bathy_0 <- read_sf("data/ne_10m_bathymetry_L_0.shp") bathy_200 <- read_sf("data/ne_10m_bathymetry_K_200.shp") ``` ] .right-plot[ <img src="R-session-06-mapping_files/figure-html/unnamed-chunk-50-1.png" width="80%" style="display: block; margin: auto;" /> ] --- exclude = true ```r # Very tricky must use the Windows file convention (backslash and not slash) !!! bathy_0 <- read_sf("data/ne_10m_bathymetry_L_0.shp") bathy_200 <- read_sf("data/ne_10m_bathymetry_K_200.shp") theme_set(theme_bw()) ggplot() + geom_sf(data = world, fill="grey90", color="grey90") + geom_sf(data = bathy_0, fill="deepskyblue", color="deepskyblue") + geom_sf(data=bathy_200, fill="white", color="white")+ coord_sf(xlim=c(-20,40), ylim=c(30,70)) + geom_point(data=filter(bolido, bolido_pct >0), aes(x=longitude, y=latitude, size=bolido_pct), color="red")+ geom_text(data = world_centroids, aes(x = X, y=Y, label=name), size=3) + xlab("Longitude") + ylab("Latitude") + labs(size = "Bolido %") ``` --- layout: false class: middle, inverse # Recap .font150[ * Simple features * Static maps * Plotting your data * Interactive map ] --- background-image: url(img/course-logo.png) background-position: right top 30px background-size: 45% class: inverse # Topics to explore on your own .font150[ * Strings and date manipulation * Text mining * Web mining * Markdown: books, web sites, presentations * Creating Packages * Interface to Databases (MySQL) ] --- layout: false background-image: url(img/course-logo.png) background-position: center bottom 30px background-size: 45% class: center, inverse .font200[**C'est fini...**]