The R package dddr
is a vctrs
-based package for working with three-diensional spatial data. It gives three-dimensional objects like points, velocities, and rotations first-class vector status in R, enabling usage as column types within data.frame
and tibble
.
In contrast to most spatial R packages like sf
or rspatial
that work with geographic, 2-dimensional data, dddr
works best with 3-dimensional data. The origin of this package was to analyze behavioral data (e.g, hand motion, head direction) in studies of virtual and augmented reality.
library(tidyverse) library(dddr)
spiral <- tibble(i = seq(0, 10*pi, 0.05)) %>% mutate( # vector3s are created using three numeric vector arguments, # and thanks to dplyr, can refer to other columns in the dataframe circular_part = vector3(x=cos(i), y=sin(i), z=0), forward_part = vector3(x=0, y=0, z=i/15), # vector3s can be added together and multiplied by numerics spiral_part = circular_part * i / 30 + forward_part ) spiral %>% head(10)
spiral %>% # field access uses the $ operator ggplot(aes(vector3=spiral_part)) + stat_point3(geom="point") + #geom_path3() + coord_look_at_front()
spiral %>% mutate( # rotations can be specified using quaternions, axis / angle, or even from / to vectors spiral_rotated = rotate(spiral_part, axis=vector3(0, 1, 0), angle=pi/4) ) %>% ggplot(aes(x=spiral_rotated$x, y=spiral_rotated$y)) + geom_point() + geom_path() + coord_equal()
```{R eval=FALSE} simple_dddr_plot <- function() { spiral <- tibble(i = seq(0, 10*pi, 0.05)) %>% mutate( circular_part = vector3(x=cos(i), y=sin(i), z=i/15), forward_part = vector3(x=0, y=0, z=i/15), spiral_part = circular_part * i / 30 + forward_part )
spiral %>% ggplot() + stat_point3(aes(vector3=spiral_part)) + coord_look_at_front() }
# Installation ```{R, eval=FALSE} install.packages("devtools") # if you have not installed "devtools" package # For the most recent packaged & released version devtools::install_github("MrMallIronmaker/dddr@*release") # For the development version devtools::install_github("MrMallIronmaker/dddr")
If you have questions in how to use this library, what this library is useful for, or if it has any particular features, it would be helpful to contact me directly at mrmillr at stanford.edu
. This project is in its early development stages, and I want to know how you want to use the library / are using the library.
Contributions are welcome! The issue tracker in this repo can be used for bug reports, feature requests, and questions - whatever you might need.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.