Learn R Programming

deeptime

Overview

deeptime extends the functionality of other plotting packages (notably {ggplot2}) to help facilitate the plotting of data over long time intervals, including, but not limited to, geological, evolutionary, and ecological data. The primary goal of deeptime is to enable users to add highly customizable timescales to their visualizations. Other functions are also included to assist with other areas of deep time visualization.

Installation

# get the stable version from CRAN
install.packages("deeptime")

# or get the development version from github
# install.packages("devtools")
devtools::install_github("willgearty/deeptime")

Usage

Load packages

library(deeptime)
library(ggplot2)
library(dplyr)

Add one or more timescales to virtually any ggplot2 plot!

The main function of deeptime is coord_geo(), which functions just like coord_trans() from {ggplot2}. You can use this function to add highly customizable timescales to a wide variety of ggplots.

library(divDyn)
data(corals)

# this is not a proper diversity curve but it gets the point across
coral_div <- corals %>% filter(stage != "") %>%
  group_by(stage) %>%
  summarise(n = n()) %>%
  mutate(stage_age = (stages$max_age[match(stage, stages$name)] +
                        stages$min_age[match(stage, stages$name)])/2)
ggplot(coral_div) +
  geom_line(aes(x = stage_age, y = n)) +
  scale_x_reverse("Age (Ma)") +
  ylab("Coral Genera") +
  coord_geo(xlim = c(250, 0), ylim = c(0, 1700)) +
  theme_classic(base_size = 16)

Lots of timescales available!

# Load packages
library(gsloid)

# Plot two different timescales
ggplot(lisiecki2005) +
  geom_line(aes(x = d18O, y = Time / 1000), orientation = "y") +
  scale_y_reverse("Time (Ma)") +
  scale_x_reverse("\u03B418O") +
  coord_geo(
    dat = list("Geomagnetic Polarity Chron",
               "Planktic foraminiferal Primary Biozones"),
    xlim = c(6, 2), ylim = c(5.5, 0), pos = list("l", "r"),
    rot = 90, skip = "PL4", size = list(5, 4)
  ) +
  theme_classic(base_size = 16)

Super flexible, supports multiple layouts, and works great with other packages!

# Load packages
library(ggtree)
library(rphylopic)

# Get vertebrate phylogeny
library(phytools)
data(vertebrate.tree)

vertebrate.tree$tip.label[vertebrate.tree$tip.label ==
                            "Myotis_lucifugus"] <- "Vespertilioninae"
vertebrate_data <- data.frame(species = vertebrate.tree$tip.label,
                              name = vertebrate.tree$tip.label)

# Plot the phylogeny with a timescale
revts(ggtree(vertebrate.tree, size = 1)) %<+%
  vertebrate_data +
  geom_phylopic(aes(name = name), size = 25) +
  scale_x_continuous("Time (Ma)", breaks = seq(-500, 0, 100),
                     labels = seq(500, 0, -100), limits = c(-500, 0),
                     expand = expansion(mult = 0)) +
  scale_y_continuous(guide = NULL) +
  coord_geo_radial(dat = "periods", end = 0.5 * pi) +
  theme_classic(base_size = 16)

Does lots of other things too!

Plot fossil occurence ranges

library(palaeoverse)

# Filter occurrences
occdf <- subset(tetrapods, accepted_rank == "genus")
occdf <- subset(occdf, accepted_name %in%
                  c("Eryops", "Dimetrodon", "Diadectes", "Diictodon",
                    "Ophiacodon", "Diplocaulus", "Benthosuchus"))

# Plot occurrences
ggplot(data = occdf) +
  geom_points_range(aes(x = (max_ma + min_ma)/2, y = accepted_name)) +
  scale_x_reverse(name = "Time (Ma)") +
  ylab(NULL) +
  coord_geo(pos = list("bottom", "bottom"), dat = list("stages", "periods"),
            abbrv = list(TRUE, FALSE), expand = TRUE, size = "auto") +
  theme_classic(base_size = 16)

Use standardized geological patterns

# Load packages
library(rmacrostrat)
library(ggrepel)

# Retrieve the Macrostrat units in the San Juan Basin column
san_juan_units <- get_units(column_id = 489, 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

# Get lithology definitions
liths <- def_lithologies()

# Get the primary lithology for each unit
san_juan_units$lith_prim <- sapply(san_juan_units$lith, function(df) {
  df$name[which.max(df$prop)]
})

# Get the pattern codes for those lithologies
san_juan_units$pattern <- factor(liths$fill[match(san_juan_units$lith_prim, liths$name)])

# Plot with pattern fills
ggplot(san_juan_units, aes(ymin = b_age, ymax = t_age,
                           xmin = x_min, xmax = x_max)) +
  # Plot units, patterned by rock type
  geom_rect(aes(fill = pattern), color = "black") +
  scale_fill_geopattern(name = NULL,
                        breaks = factor(liths$fill), labels = liths$name) +
  # Add text labels
  geom_text_repel(aes(x = x_max, y = m_age, label = unit_name),
                  size = 3.5, hjust = 0, force = 2,
                  min.segment.length = 0, direction = "y",
                  nudge_x = rep_len(x = c(2, 3), length.out = 17)) +
  # Add geological time scale
  coord_geo(pos = "left", dat = list("stages"), rot = 90) +
  # Reverse direction of y-axis
  scale_y_reverse(limits = c(145, 66), n.breaks = 10, name = "Time (Ma)") +
  # Remove x-axis guide and title
  scale_x_continuous(NULL, guide = NULL) +
  # Choose theme and font size
  theme_classic(base_size = 14) +
  # Make tick labels black
  theme(legend.position = "bottom", legend.key.size = unit(1, 'cm'),
        axis.text.y = element_text(color = "black"))

Copy Link

Version

Install

install.packages('deeptime')

Monthly Downloads

1,005

Version

2.2.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

William Gearty

Last Published

June 19th, 2025

Functions in deeptime (2.2.0)

getScaleData

Get geological timescale data
geom_text_phylo

Label nodes on a phylogenetic tree plotted with ggtree
get_scale_data

Get geological timescale data
geo_pattern

Get a FGDC geologic plotting pattern
geom_phylomorpho

Plot a 2-D phylomorphospace in ggplot2
geom_points_range

Display points and their range
facet_nested_wrap_color

Ribbon of panels with nested colored strips
facet_wrap_color

Wrap a 1d ribbon of panels into 2d with colored strips
facet_grid_color

Lay out panels in a grid with colored strips
facet_nested_color

Layout panels in a grid with nested colored strips
ggarrange2

Combine and arrange multiple ggplot-like objects
guide_geo

Geological timescale axis guide
gtable_frame2

Decompose a ggplot gtable
panel.disparity

Combined wireframe and cloud panel
scale_color_geo

Geological Time Scale color scales
grid.pattern_geo

Plot an individual FGDC pattern using grid
scale_fill_geopattern

Geologic pattern fill scale
gggeo_scale_old

Add a geologic scale on top of ggplots
periods

Period data from the International Commission on Stratigraphy (v2024/12)
gggeo_scale

Add a geologic scale below ggplots using grid
stages

Stage data from the International Commission on Stratigraphy (v2024/12)
deeptime-package

deeptime: Plotting Tools for Anyone Working in Deep Time
eons

Eon data from the International Commission on Stratigraphy (v2024/12)
disparity_through_time

Disparity through time plot using lattice
coord_trans_xy

Transformed XY Cartesian coordinate system
coord_geo_polar

Polar coordinate system with geological timescale
coord_trans_flip

Transformed and flipped Cartesian coordinate system
eras

Era data from the International Commission on Stratigraphy (v2024/12)
coord_geo

Transformed coordinate system with geological timescale
coord_geo_radial

Enhanced polar coordinate system with geological timescale
epochs

Epoch data from the International Commission on Stratigraphy (v2024/12)