coord_geo_polar: Polar coordinate system with geological timescale

View source: R/coord_geo_polar.R

coord_geo_polarR Documentation

Polar coordinate system with geological timescale

Description

coord_geo_polar behaves similarly to ggplot2::coord_polar() in that it occurs after statistical transformation and will affect the visual appearance of geoms. The main difference is that it also adds a geological timescale to the background of the plot.

Usage

coord_geo_polar(
  dat = "periods",
  theta = "y",
  start = -pi/2,
  direction = -1,
  clip = "off",
  fill = NULL,
  alpha = 1,
  lwd = 0.25,
  color = "grey80",
  lty = "solid",
  neg = TRUE,
  prop = 1
)

Arguments

dat

Either A) a string indicating a built-in dataframe with interval data from the ICS ("periods", "epochs", "stages", "eons", or "eras"), B) a string indicating a timescale from macrostrat (see list here: https://macrostrat.org/api/defs/timescales?all), or C) a custom data.frame of time interval boundaries (see Details).

theta

variable to map angle to (x or y)

start

Offset of starting point from 12 o'clock in radians. Offset is applied clockwise or anticlockwise depending on value of direction.

direction

1, clockwise; -1, anticlockwise

clip

Should drawing be clipped to the extent of the plot panel? A setting of "on" (the default) means yes, and a setting of "off" means no. For details, please see coord_cartesian().

fill

The fill color of the background. The default is to use the color column included in dat. If a custom dataset is provided with dat without a color column and without fill, a greyscale will be used. Custom fill colors can be provided with this option (overriding the color column) and will be recycled if/as necessary.

alpha

The transparency of the fill colors.

lwd

Line width for lines between intervals. Set to NULL to remove lines.

color

The color of the lines between intervals.

lty

Line type for lines between intervals.

neg

Set this to true if your theta-axis is using negative values. This is often true if you are using ggtree.

prop

This is the rotational proportion of the background that the scale takes up.

Details

If a custom data.frame is provided (with dat), it should consist of at least 2 columns of data. See data(periods) for an example.

  • The max_age column lists the oldest boundary of each time interval.

  • The min_age column lists the youngest boundary of each time interval.

  • The color column is optional and lists a color for the background for each time interval.

dat may also be a list of values and/or dataframes if multiple time scales should be added to the background. Scales will be added sequentially starting at start and going in the specified direction. By default the scales will all be equal in circular/rotational proportion, but this can be overridden with prop. If dat is a list, fill, alpha, lwd, lty, color, neg, and prop can also be lists. If these lists are not as long as dat, the elements will be recycled. If individual values (or vectors) are used for these parameters, they will be applied to all time scales (and recycled as necessary).

If the sum of the prop values is greater than 1, the proportions will be scaled such that they sum to 1. However, the prop values may sum to less than 1 if the user would like blank space in the background.

The axis.line.r, axis.text.r, axis.ticks.r, and axis.ticks.length.r ggplot2 theme elements can be modified just like their x and y counterparts to change the appearance of the radius axis. The default settings work well for a horizontal axis pointing towards the right, but these theme settings will need to be modified for other orientations. The default value for axis.line.r is element_line(). The default value for axis.text.r is element_text(size = 3.5, vjust = -2, hjust = NA). The default value for axis.ticks.r is element_line(). The default value for axis.ticks.length.r is unit(1.5, "points"). However, note that the units for this element are meaningless and only the numeric value will be used (but a unit must still be used).

Examples

library(ggplot2)

library(ggtree)
set.seed(1)
tree <- rtree(100)
# single scale
revts(ggtree(tree)) +
  coord_geo_polar(dat = "stages")

# multiple scales
revts(ggtree(tree)) +
  coord_geo_polar(
    dat = list("stages", "periods"), alpha = .5,
    prop = list(0.75, .25), start = pi / 4, lty = "dashed"
  ) +
  scale_y_continuous(expand = expansion(mult = c(0.02, 0.02))) +
  theme(axis.text.r = element_text(size = 3.5, hjust = .75, vjust = .75))


library(ggplot2)
library(paleotree)
data(RaiaCopesRule)
ggtree(ceratopsianTreeRaia,
       position = position_nudge(x = -ceratopsianTreeRaia$root.time)) +
  coord_geo_polar(dat = "stages")


deeptime documentation built on Feb. 16, 2023, 10:59 p.m.