Transforming coordinate systems"

knitr::opts_chunk$set(collapse = TRUE, fig.width = 7, fig.height = 5, fig.align = "center")
`{ggplot2}` has many built-in [coordinate systems](https://ggplot2-book.org/coord.html) which are used to both 1) produce the two-dimensional position of the plotted data and 2) draw custom axes and panel backgrounds. `coord_geo()` uses this second purpose to draw special axes that include timescales. However, __deeptime__ also includes a number of other coordinate systems whose primary function is to modify the way data is plotted. To demonstrate this, we'll first need to load some packages. wzxhzdk:1 ## coord_trans meets coord_flip One limitation of the traditional `coord_trans()` function in `{ggplot2}` is that you can not flip the axes while also transforming the axes. Historically, you would need to either 1) use `scale_x_continuous()` or `scale_y_continuous()` to transform one or both of your axes (which could result in the untransparent loss of data) in combination with `coord_flip()` or 2) transform your data before supplying it to `ggplot()`. `coord_trans_flip()` accomplishes this without the need for `scales` or transforming your data. It works just like `coord_trans()`, with the added functionality of the axis flip from `coord_flip()`. wzxhzdk:2 Note: back in 2020, `{ggplot2}` [updated](https://www.tidyverse.org/blog/2020/03/ggplot2-3-3-0/#bi-directional-geoms-and-stats) all the directional stats and geoms (e.g., boxplots and histograms) to work in both directions based on the aesthetic mapping. This somewhat makes this function redundant, but I still find it useful. ## 2D linear transformations Another limitation of the traditional `coord_trans()` is that each axis is transformed independently. `coord_trans_xy()` expands this functionality to allow for a two-dimensional linear transformation as generated by `ggforce::linear_trans()`. This allows for rotations, stretches, shears, translations, and reflections. A dummy example using the `?mtcars` dataset from `{ggplot2}` is included below. While applications of this functionality may seem abstract for real data, see the [plotting traits](traits.html) article for a potential real-world application using species trait data. wzxhzdk:3


Try the deeptime package in your browser

Any scripts or data that you put into this service are public.

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