knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Eventually, this package aims to provide a skeleton for vctrs-based scales and coordinate system for ggplot2 that can be extended for vctrs-based classes.
It is pretty bare-bones at the moment and depends on the development version of ggplot2, and I wouldn't recommend incorporating this pacakge in anything else than a sandbox to play around with.
You can install the development version from GitHub with:
# install.packages("devtools") devtools::install_github("teunbrand/ggvctrcoords")
The main problem that I watned to tackle is to walk through the internals of ggplot2 with custom classes of vectors that preserve attributes and classes. As shown below, the data for x
has lost attributes.
library(ggplot2) df <- data.frame( x = structure(1:10, foo = "bar"), y = 10:1 ) plot <- ggplot(df, aes(x, y)) + geom_point() lay_dat <- layer_data(plot) attributes(lay_dat$x)
The basic premise of this package is that one should be able to march a vector through the internals of ggplot if they have appropriate methods. One such example is implemented in the interval
class:
library(ggvctrcoords) x <- interval(3:5, c(4,6,8)) print(x)
We can see that the class survives the internals of ggplot2 by asking for the layer_data()
of the plot:
df <- data.frame( x = x, y = 1:3 ) plot <- ggplot(df, aes(x, y)) + geom_point() + coord_cartesian_vctr() lay_dat <- layer_data(plot) print(lay_dat)
This makes it possible to perform context dependant evaluation of the class. For example, the interval
class gives the start positions when asked for xmin
and the end positions if asked for xmax
.
ggplot(df, aes(xmin = x, xmax = x, ymin = y - 0.4, ymax = y + 0.4)) + geom_rect() + coord_cartesian_vctr()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.