# rmacrostrat The goal of `rmacrostrat` is to streamline and improve accessibility to the geological database [Macrostrat](https://macrostrat.org). The package provides functionality for querying the database via the dedicated application programming interface (API) and retrieving various geological data (e.g., lithostratigraphic units) and definitions/metadata associated with those data and Macrostrat more broadly. ## Development team - [Lewis A. Jones](mailto:Lewis.Jones@ucl.ac.uk), University College London - [William Gearty](mailto:willgearty@gmail.com), American Museum of Natural History - [Christopher D. Dean](mailto:christopherdaviddean@gmail.com), University College London - [Bethany J. Allen](mailto:bethany.janet.allen@gfz.de), GFZ Helmholtz Centre for Geosciences ## Installation The stable version of `rmacrostrat` can be installed from CRAN using: ``` r install.packages("rmacrostrat") ``` You can install the development version of `rmacrostrat` from [GitHub](https://github.com/) with: ``` r # install.packages("devtools") devtools::install_github("palaeoverse/rmacrostrat") ``` ## Example usage A minimal example of getting and plotting a stratigraphic column for the San Juan Basin: ``` r # Load packages library(rmacrostrat) library(ggplot2) library(ggrepel) library(deeptime) # Get the column definition of the San Juan Basin column_def <- def_columns(column_name = "San Juan Basin") # Using the column ID, retrieve all units of Cretaceous age san_juan_units <- get_units(column_id = column_def$col_id, interval_name = "Cretaceous") # Specify x_min and x_max in dataframe san_juan_units$x_min <- 0 san_juan_units$x_max <- 1 # Tweak values for overlapping units san_juan_units$x_max[10] <- 0.5 san_juan_units$x_min[11] <- 0.5 # Add midpoint age for plotting san_juan_units$m_age <- (san_juan_units$b_age + san_juan_units$t_age) / 2 # Standardize and correct unit names according to USGS Geolex san_juan_units$unit_name <- gsub(pattern = "Kirkland", replacement = "Kirtland", x = san_juan_units$unit_name) san_juan_units$unit_name <- gsub(pattern = "Graneros Mbr", replacement = "Graneros Shale Mbr", x = san_juan_units$unit_name) san_juan_units$unit_name <- gsub(pattern = "Sanostee Mbr", replacement = "Sanastee Sandstone Mbr", x = san_juan_units$unit_name) # Plot stratigraphic column ggplot(san_juan_units, aes(ymin = b_age, ymax = t_age, xmin = x_min, xmax = x_max)) + # Plot units, colored by rock type geom_rect(fill = san_juan_units$color, color = "black") + # Add text labels geom_text_repel(aes(x = x_max, y = m_age, label = unit_name), box.padding = 0.1, nudge_x = 3, size = 3.5) + # Reverse direction of y-axis scale_y_reverse(limits = c(145, 66), n.breaks = 10, name = "Time (Ma)") + # Theming theme_classic() + theme(legend.position = "none", axis.line.x = element_blank(), axis.title.x = element_blank(), axis.text.x = element_blank(), axis.ticks.x = element_blank()) + # Add geological time scale coord_geo(pos = "left", dat = list("stages"), rot = 90) ``` ![](reference/figures/strat_column.png) A minimal example of getting and plotting outcrop data for the Hell Creek formation: ``` r # Load libraries library(rmacrostrat) library(ggplot2) library(ggspatial) # Get data for the chosen formation hc_def <- def_strat_names(strat_name = "Hell Creek", rank = "Fm") # Get spatial outcrop data for the formation hc <- get_map_outcrop(strat_name_id = hc_def$strat_name_id, sf = TRUE) # Plot the map ggplot() + geom_sf(data = hc, fill = "#C7622B", lwd = 0) + coord_sf(xlim = c(-112, -97), ylim = c(44, 50)) + annotation_north_arrow(location = "br", pad_y = unit(0.75, "cm"), height = unit(1, "cm"), width = unit(1, "cm")) + annotation_scale(location = "br", width_hint = 0.3) + theme_bw() ``` ![](reference/figures/hell_creek_outcrop.png) A minimal example of getting and plotting the number of marine units through time for North America: ``` r # Load libraries library(rmacrostrat) library(ggplot2) library(deeptime) # Get all carbonate units for North America units <- get_units(environ_class = "marine", interval_name = "Phanerozoic", project_id = 1) # Add mid age for units units$mid_age <- (units$b_age + units$t_age) / 2 # Plot data ggplot(units, aes(x = mid_age)) + geom_histogram(binwidth = 10, center = 5, color = "black", fill = "#add8e6") + scale_y_continuous("Number of marine units") + scale_x_reverse("Time (Ma)", limits = c(538.8, 0)) + theme_bw() + theme(legend.title = element_blank(), legend.position.inside = c(0.1, 0.9)) + coord_geo() ``` ![](reference/figures/marine_units.png) Extensive example usage of `rmacrostrat` is provided in the package vignettes/tutorials. These can be accessed [online](https://rmacrostrat.palaeoverse.org/articles/) or in R via: ``` r browseVignettes(package = "rmacrostrat") ``` # How to contribute? If you are interested in contributing to the `rmacrostrat` R package, you can do so by following these [guidelines](https://rmacrostrat.palaeoverse.org/CONTRIBUTING.html). We have also adopted a set of [standards and structure](https://palaeoverse.palaeoverse.org/articles/structure-and-standards.html) to broadly follow for contributing to Palaeoverse R packages. If you would like to contribute to `rmacrostrat`, we strongly advise reading this document. # Code of Conduct As with any community project, society, or meeting we feel it is important to established some expectations of behaviour in the `rmacrostrat` community. Please read our [code of conduct](https://rmacrostrat.palaeoverse.org/CODE_OF_CONDUCT.html), and reach out if you ever face any issues. Everyone has the right to live and work in a harassment-free environment. # Citation If you use the `rmacrostrat` R package in your work, please cite as: Jones, L.A., Dean, C.D., Gearty, W., and Allen, B.J. 2024. rmacrostrat: An R package for accessing and retrieving data from the Macrostrat geological database. *Geosphere*, v. 20:6, 1456–1467. DOI: [10.1130/GES02815.1](https://doi.org/10.1130/GES02815.1). ![](reference/figures/logo.png) Hexlogo by Miranta Kouvari # Package index ## Macrostrat data entities Functions for retrieving entities that exist as part of the Macrostrat data hierarchy (i.e., units, sections/packages, and columns). - [`get_units()`](https://rmacrostrat.palaeoverse.org/reference/get_units.md) : Retrieve Macrostrat unit data - [`get_sections()`](https://rmacrostrat.palaeoverse.org/reference/get_sections.md) : Retrieve Macrostrat section data - [`get_columns()`](https://rmacrostrat.palaeoverse.org/reference/get_columns.md) : Retrieve Macrostrat column data - [`def_columns()`](https://rmacrostrat.palaeoverse.org/reference/def_columns.md) : Define Macrostrat columns - [`get_age_model()`](https://rmacrostrat.palaeoverse.org/reference/get_age_model.md) : Retrieve Macrostrat column age models ## Geologic map elements and sources Functions for retrieving various elements (e.g., shapes, points, and legends) and metadata of geologic maps that have been ingested into the Macrostrat database. - [`get_map_outcrop()`](https://rmacrostrat.palaeoverse.org/reference/get_map_outcrop.md) : Retrieve geologic map outcrop shape element data - [`get_map_points()`](https://rmacrostrat.palaeoverse.org/reference/get_map_points.md) : Retrieve geologic map point shape element data - [`get_map_legends()`](https://rmacrostrat.palaeoverse.org/reference/get_map_legends.md) : Retrieve geologic map legend data - [`get_tiles()`](https://rmacrostrat.palaeoverse.org/reference/get_tiles.md) : Retrieve Macrostrat vectorized tiles - [`def_sources()`](https://rmacrostrat.palaeoverse.org/reference/def_sources.md) : Retrieve geologic map source definitions ## External data linked to Macrostrat entities Functions for retrieving various external data (e.g., Paleobiology Database fossil occurrences, rock sample measurements) that have been linked to Macrostrat entities. - [`get_fossils()`](https://rmacrostrat.palaeoverse.org/reference/get_fossils.md) : Retrieve collections from the Paleobiology Database - [`get_eodp()`](https://rmacrostrat.palaeoverse.org/reference/get_eodp.md) : Retrieve core data from ocean drilling programs - [`def_drilling_sites()`](https://rmacrostrat.palaeoverse.org/reference/def_drilling_sites.md) : Define objects associated with eODP - [`get_measurements()`](https://rmacrostrat.palaeoverse.org/reference/get_measurements.md) : Retrieve geological measurements - [`def_measurements()`](https://rmacrostrat.palaeoverse.org/reference/def_measurements.md) : Define measurements ## Paleogeography Functions for returning paleogeographic reconstructions and associated plate definitions. - [`get_paleogeography()`](https://rmacrostrat.palaeoverse.org/reference/get_paleogeography.md) : Retrieve paleogeographic geometries - [`def_plates()`](https://rmacrostrat.palaeoverse.org/reference/def_plates.md) : Define tectonic plates ## Macrostrat database definitions Retrieve definitions for various data types stored within the Macrostrat database. - [`catalog()`](https://rmacrostrat.palaeoverse.org/reference/catalog.md) : Retrieve a complete set of definitions ### Geologic features and attributes - [`def_environments()`](https://rmacrostrat.palaeoverse.org/reference/def_environments.md) : Define environments - [`def_lithologies()`](https://rmacrostrat.palaeoverse.org/reference/def_lithologies.md) : Define lithologies - [`def_lithology_att()`](https://rmacrostrat.palaeoverse.org/reference/def_lithology_att.md) : Define lithology attributes - [`def_econs()`](https://rmacrostrat.palaeoverse.org/reference/def_econs.md) : Define economic resources - [`def_grain_sizes()`](https://rmacrostrat.palaeoverse.org/reference/def_grain_sizes.md) : Define grain sizes - [`def_minerals()`](https://rmacrostrat.palaeoverse.org/reference/def_minerals.md) : Define minerals - [`def_structures()`](https://rmacrostrat.palaeoverse.org/reference/def_structures.md) : Define geological structure - [`def_measurements()`](https://rmacrostrat.palaeoverse.org/reference/def_measurements.md) : Define measurements ### Stratigraphic names - [`def_strat_names()`](https://rmacrostrat.palaeoverse.org/reference/def_strat_names.md) : Define stratigraphic names - [`def_strat_name_concepts()`](https://rmacrostrat.palaeoverse.org/reference/def_strat_name_concepts.md) : Define stratigraphic name concepts ### Timescales and time intervals - [`def_timescales()`](https://rmacrostrat.palaeoverse.org/reference/def_timescales.md) : Define timescales - [`def_intervals()`](https://rmacrostrat.palaeoverse.org/reference/def_intervals.md) : Define Macrostrat time intervals ### Miscellany - [`def_columns()`](https://rmacrostrat.palaeoverse.org/reference/def_columns.md) : Define Macrostrat columns - [`def_drilling_sites()`](https://rmacrostrat.palaeoverse.org/reference/def_drilling_sites.md) : Define objects associated with eODP - [`def_plates()`](https://rmacrostrat.palaeoverse.org/reference/def_plates.md) : Define tectonic plates ## Macrostrat database metadata Functions for retrieving various metadata about the overall Macrostrat database. - [`get_stats()`](https://rmacrostrat.palaeoverse.org/reference/get_stats.md) : Retrieve Macrostrat database statistics - [`def_projects()`](https://rmacrostrat.palaeoverse.org/reference/def_projects.md) : Retrieve metadata for Macrostrat projects - [`def_sources()`](https://rmacrostrat.palaeoverse.org/reference/def_sources.md) : Retrieve geologic map source definitions - [`def_references()`](https://rmacrostrat.palaeoverse.org/reference/def_references.md) : Define references # Articles ### All vignettes - [Making a geologic outcrop map with rmacrostrat](https://rmacrostrat.palaeoverse.org/articles/geologic-map.md): - [Quantifying the geological completeness of paleontological sampling in North America](https://rmacrostrat.palaeoverse.org/articles/geological-completeness.md): - [Plotting a stratigraphic column with rmacrostrat](https://rmacrostrat.palaeoverse.org/articles/stratigraphic-column.md):