knitr::opts_chunk$set(collapse = TRUE, fig.width = 7, fig.height = 5, fig.align = "center")
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. Before we begin, let's load some necessary packages first. wzxhzdk:1 ## Adding geological timescales First, let's summarize some coral data from the `divDyn` package to generate a diversity curve that we'll be able to plot: wzxhzdk:2 Now, we can plot the data and add a geological timescale. The default behavior is to add the ICS periods to the bottom axis. The data used for this is included in the package (`?periods`) along with data for `?eons`, `?stages`, `?epochs`, and `?eras`. Note that the function assumes that age is decreasing towards the present. wzxhzdk:3 ### Scales on other axes You can add the timescale to whichever axis you'd like by setting the `pos` argument. For example, `pos = "left"` can be used to put the timescale on the left axis. Also, note that we're using the "Geomagnetic Polarity Chron" timescale here. This is one of more than 35 regional and global timescales that are available through __deeptime__ from the [Macrostrat](https://macrostrat.org/api/defs/timescales?all) database (see `get_scale_data()`). wzxhzdk:4
plot of oxygen isotope data with a geomagnetic polarity chron timescale on the y-axis
### Add multiple timescales You can also add multiple timescales by providing a list for `pos`. Other arguments can be lists or single values (either of which will be recycled if necessary). In this case we are adding the "Geomagnetic Polarity Chron" timescale to the left axis and the "Planktic foraminiferal Primary Biozones" timescale to the right axis. wzxhzdk:5
plot of oxygen isotope data with a geomagnetic polarity chron timescale on the left y-axis and plantic foraminiferal biozones on the right y-axis
### Stack multiple scales You can even stack multiple timescales on the same side. Scales are added from the inside to the outside. Here we are stacking periods and eras. wzxhzdk:6 ### Timescales and faceted plots `coord_geo()` synergizes well with faceted plots. You can change on which facets the timescale is plotted by changing the `scales` argument in `facet_wrap()`. The default behavior is to only include the timescale on the bottom-most panel. This behavior works similarly with `facet_grid()`. wzxhzdk:7 By specifying `scales = "free_x"`, you can add a geological time scale to each panel. wzxhzdk:8 ### Resize labels to fit inside interval rectangles `coord_geo()` can use the `{ggfittext}` package to resize the interval labels. This can be enabled by setting `size` to `"auto"`. Additional arguments can be passed to `ggfittext::geom_fit_text()` as a list using the `fittext_args` argument. wzxhzdk:9 ## Scales on discrete axes `coord_geo()` will automatically detect if your axis is discrete. The categories of the discrete axis (which can be reordered using the `limits` argument of `scale_x_discrete()`/`scale_y_discrete()`) should match the `name` column of the timescale data (`dat`). You can use the arguments of `theme()` and `scale_[x/y]_discrete()` to optionally remove the labels and tick marks. wzxhzdk:10 ### Custom discrete scales You can also supply your own pre-discretized scale data by setting the `dat_is_discrete` parameter to `TRUE`. Custom scales should always have `name`, `max_age`, and `min_age` columns. Optional columns include `abbr` for abbreviations, `color` for background colors, and `lab_color` for interval label colors. You can even have one scale with auto-discretized intervals and one scale with pre-discretized intervals. wzxhzdk:11 ## More advanced topics Looking to learn about more advanced features of __deeptime__? Look no further: - [Plotting phylogenies with timescales](phylogenies.html) - [Plotting trait data](traits.html) - [Combining and arranging plots](ggarrange2.html) - [Additional ggplot coordinate systems](coord.html)


willgearty/deeptime documentation built on April 5, 2024, 3:24 a.m.