Package transformr. December 9, 2018

Similar documents
Package tweenr. September 27, 2018

Package sfdct. August 29, 2017

Package farver. November 20, 2018

Package geojsonsf. R topics documented: January 11, Type Package Title GeoJSON to Simple Feature Converter Version 1.3.

Package geoops. March 19, 2018

Package nngeo. September 29, 2018

Package cattonum. R topics documented: May 2, Type Package Version Title Encode Categorical Features

Package repec. August 31, 2018

Package datasets.load

Package ECctmc. May 1, 2018

Package fastdummies. January 8, 2018

Package geogrid. August 19, 2018

Package mapsapi. March 12, 2018

Package fst. December 18, 2017

Package messaging. May 27, 2018

Package jpmesh. December 4, 2017

Package spark. July 21, 2017

Package gggenes. R topics documented: November 7, Title Draw Gene Arrow Maps in 'ggplot2' Version 0.3.2

Package velox. R topics documented: December 1, 2017

Package validara. October 19, 2017

Package bigreadr. R topics documented: August 13, Version Date Title Read Large Text Files

Package facerec. May 14, 2018

Package sfc. August 29, 2016

Package qualmap. R topics documented: September 12, Type Package

Package tidytransit. March 4, 2019

Package kdtools. April 26, 2018

Package packcircles. April 28, 2018

Package crossword.r. January 19, 2018

Package smoothr. April 4, 2018

Package comparedf. February 11, 2019

Package ggimage. R topics documented: December 5, Title Use Image in 'ggplot2' Version 0.1.0

Package curry. September 28, 2016

Package mdftracks. February 6, 2017

Package ggimage. R topics documented: November 1, Title Use Image in 'ggplot2' Version 0.0.7

Package processanimater

Package postgistools

Package canvasxpress

Package lexrankr. December 13, 2017

Package IATScore. January 10, 2018

Package fst. June 7, 2018

Package githubinstall

Package RTriangle. January 31, 2018

Package textrecipes. December 18, 2018

Package AhoCorasickTrie

Package strat. November 23, 2016

Package coga. May 8, 2018

Package keyholder. May 19, 2018

Package robotstxt. November 12, 2017

Package editdata. October 7, 2017

Package ecoseries. R topics documented: September 27, 2017

Package tidyimpute. March 5, 2018

Package readobj. November 2, 2017

Package TVsMiss. April 5, 2018

Package oec. R topics documented: May 11, Type Package

Package rsppfp. November 20, 2018

Package fastrtext. December 10, 2017

Package semver. January 6, 2017

Package kirby21.base

Package available. November 17, 2017

Package tidyselect. October 11, 2018

Package cancensus. February 4, 2018

Package jstree. October 24, 2017

Package projector. February 27, 2018

Package purrrlyr. R topics documented: May 13, Title Tools at the Intersection of 'purrr' and 'dplyr' Version 0.0.2

Package understandbpmn

Package sylcount. April 7, 2017

Package combiter. December 4, 2017

Package Rsomoclu. January 3, 2019

Package clipr. June 23, 2018

Package spelling. December 18, 2017

Package raker. October 10, 2017

Package mapedit. R topics documented: March 2, Title Interactive Editing of Spatial Data in R

Package docxtools. July 6, 2018

Package d3plus. September 25, 2017

Package Numero. November 24, 2018

Package hypercube. December 15, 2017

Package tibble. August 22, 2017

Package rcv. August 11, 2017

Package slickr. March 6, 2018

Package barcoder. October 26, 2018

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

Package readxl. April 18, 2017

Package censusr. R topics documented: June 14, Type Package Title Collect Data from the Census API Version 0.0.

Package PCADSC. April 19, 2017

Package rtext. January 23, 2019

Package pwrab. R topics documented: June 6, Type Package Title Power Analysis for AB Testing Version 0.1.0

Package mazealls. December 12, 2017

Package meme. November 2, 2017

Package ompr. November 18, 2017

Package wrswor. R topics documented: February 2, Type Package

Package SimilaR. June 21, 2018

Package meme. December 6, 2017

Package timechange. April 26, 2018

Package particles. February 26, 2018

Package postal. July 27, 2018

Package rpostgislt. March 2, 2018

Package triebeard. August 29, 2016

Package pinyin. October 17, 2018

Package osmdata. February 22, 2018

Package splithalf. March 17, 2018

Transcription:

Type Package Title Polygon and Path Transformations Version 0.1.1 Date 2018-12-04 Package transformr December 9, 2018 Maintainer Thomas Lin Pedersen <thomasp85@gmail.com> In order to smoothly animate the transformation of polygons and paths, many aspects needs to be taken into account, such as differing number of control points, changing center of rotation, etc. The 'transformr' package provides an extensive framework for manipulating the shapes of polygons and paths and can be seen as the spatial brother to the 'tweenr' package. License MIT + file LICENSE Encoding UTF-8 SystemRequirements C++11 LazyData true Imports Rcpp (>= 0.12.15), tweenr, rlang, sf, lpsolve Suggests magrittr LinkingTo Rcpp RoxygenNote 6.1.1 URL https://github.com/thomasp85/transformr BugReports https://github.com/thomasp85/transformr/issues NeedsCompilation yes Author Thomas Lin Pedersen [cre, aut] Repository CRAN Date/Publication 2018-12-09 16:30:02 UTC 1

2 simple_shapes R topics documented: transformr-package..................................... 2 simple_shapes........................................ 2 st_normalize......................................... 4 tween_path......................................... 4 tween_polygon....................................... 6 tween_sf........................................... 8 Index 10 transformr-package transformr: Polygon and Path Transformations In order to smoothly animate the transformation of polygons and paths, many aspects needs to be taken into account, such as differing number of control points, changing center of rotation, etc. The transformr package provides an extensive framework for manipulating the shapes of polygons and paths and can be seen as the spatial brother to the tweenr package. Author(s) Maintainer: Thomas Lin Pedersen <thomasp85@gmail.com> See Also Useful links: https://github.com/thomasp85/transformr Report bugs at https://github.com/thomasp85/transformr/issues simple_shapes Some different geometries to play with These functions are provided to allow you to play with somee simple shapes as you explore transformr and are also used in the examples for the different tween functions. All geometries can be returned as either a standard data.frame with x, y, and id column, or as an sf geometry of the appropriate type.

simple_shapes 3 Usage poly_circle(st = FALSE, detail = 360) poly_circles(st = FALSE, n = 3, r = 0.25, detail = 360) poly_star(st = FALSE, n = 5, r1 = 0.5) poly_star_hole(st = FALSE, n = 5, r1 = 0.5) path_spiral(st = FALSE, windings = 5) path_waves(st = FALSE, w1 = 7, w2 = 11) point_random(st = FALSE, n = 10) point_grid(st = FALSE, dim = 5) Arguments st detail n Logical. Should the geometry be returned as an sf feature? The number of points defining the shape For poly_circles the number of circles, for poly_star and poly_star_hole the number of arms, and for point_random the number of points r, r1 The radius of the geometry. r gives the radius of the circles in poly_circles and r1 gives the inner radius for poly_star/poly_star_hole, thus determining how pointy it is windings The number of revolutions in the spiral w1, w2 The frequency for the two sine waves dim the number of rows and columns in the grid Value Either a data.frame or an sf feature depending on the value of st Examples # Create a 7-pointed star poly_star(n = 7)

4 tween_path st_normalize Normalise a geometry to fit inside a unit square This is a small helper function that will take an sf geometry and fit it inside the unit square (a square centered on 0 and ranging from -1 to 1 in both dimensions). The function will retain the aspect ratio of the geometry and simply scale it down until it fits. Usage st_normalize(st) Arguments st An sf geometry such as sf, sfc, or sfg Value An object of the same type as st Examples library(sf) nc <- st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE) st_bbox(nc) nc_norm <- st_normalize(nc) st_bbox(nc_norm) tween_path Transition between path data frames This function is equivalent to tweenr::tween_state() but expects the data to have an x and y column and encode paths. Usage tween_path(.data, to, ease, nframes, id = NULL, enter = NULL, exit = NULL, match = TRUE)

tween_path 5 Arguments.data to ease nframes id enter exit match A data.frame to start from. If.data is the result of a prior tween, only the last frame will be used for the tween. The new tween will then be added to the prior tween A data.frame to end at. It must contain the same columns as.data (exluding.frame) The easing function to use. Either a single string or one for each column in the data set. The number of frames to calculate for the tween The column to match observations on. If NULL observations will be matched by position. See the Should polygons be matched by id? If FALSE then polygons will be matched by shortest distance and if any state has more polygons than the other, the other states polygons will be chopped up so the numbers match. Value A data.frame containing intermediary states Aligning paths There is less work required to align paths than there is to align polygons, simply because no rotation is possible/required, and the notion of clockwise winding order is not meaningful in the scope of paths. Still, paths need to be matched and the number of points in each pair of matched paths must be equal. Paths are matched based on relative length rather than on position and seek to minimize the change in length during transition. This is chosen from the point of view that huge elongation or contraction are much more distracting than longer travel distances. Cutting paths If the number of paths to transition between is not even, some of the paths need to be cut in order to succesfully match the paths. The cuts are distributed based on the same algorithm that distributes cuts in polygons and seek to cut the lines into as even-length pieces as possible.

6 tween_polygon Multipaths It is possible to encode multiple paths with the same id be separating them with a NA row, much in the same way as holes are encoded in polygons. If paths are not matched based on id (match = FALSE) then multipaths will simply be split into separate paths. On the other hand, if paths are matched by id all paths within a multipath will transition into the (multi)path that has the same id in the other state. tween_polygon Transition between polygon data.frames Usage This function is equivalent to tweenr::tween_state() except that data is interpeted as encoding polygons. Data is expected to have an x and y column encoding the location of corners in the polygon. tween_polygon(.data, to, ease, nframes, id = NULL, enter = NULL, exit = NULL, match = TRUE) Arguments.data to ease nframes id enter exit A data.frame to start from. If.data is the result of a prior tween, only the last frame will be used for the tween. The new tween will then be added to the prior tween A data.frame to end at. It must contain the same columns as.data (exluding.frame) The easing function to use. Either a single string or one for each column in the data set. The number of frames to calculate for the tween The column to match observations on. If NULL observations will be matched by position. See the

tween_polygon 7 match Should polygons be matched by id? If FALSE then polygons will be matched by shortest distance and if any state has more polygons than the other, the other states polygons will be chopped up so the numbers match. Value A data.frame containing intermediary states Aligning polygons transformr performs a lot of work to try to ensure the transition between different shapes are as smooth and direct as possible. The first operation is to ensure that the two end states of the polygon are both drawn clockwise, so that the transition will not contain an inversion. Second, we need to make sure that each end state is drawn with the same number of points. If not, the less detailed polygon will get points inserted at the longest edges so that the number is even between the two states. Third, we rotate the last state so as to minimize the cumulative distance between all point pairs, thus ensuring that the transition will involve a minimum of rotation. Cutting polygons If the transition involves changing the number of polygons, there are two strategies: Making polygons appear/disappear to even out the number, or cutting up the polygons in the state with the fewest in order to create the same number of polygons for the transition. In the latter case, a choice have to be made with regards to which polygons to cut, into how many, and where to cut it. transformr will distribute the number of cuts among candidate polygons based on their relative area, ensuring that it is not necessarily the largest polygon that gets all the cuts, but that divisions are distributed as fairly as possible. For deciding on where to cut the polygons they are triangulated and the triangles are then reassembled into the number of pieces needed by always adding to the smallest piece. Polygon with holes transformr support polygons with any number of holes. Holes are encoded by adding an NA row to the main enclosing polygon and appending the hole after that. Multiple holes are likewise added by simply separating them with NA rows. A hole might get cut up and disappear during transition if the polygon needs to be divided. When transitioning between polygons with holes the holes are matched by position to minimize the travel distance. If there is a mismatch between the number of holes in each end state then new zero-area holes are inserted in the centroid of the polygon with the fewest to even out the number. Examples library(magrittr) star <- poly_star_hole() circle <- poly_circle() circles <- poly_circles() tween_polygon(circle, star, 'cubic-in-out', 20) %>% tween_polygon(circles, 'cubic-in-out', 20)

8 tween_sf tween_sf Transition between data.frames containing sfc columns Usage This function is equivalent to tweenr::tween_state() except that it understands sf::sfc columns, as defined by the sf package. An sfc column is a column containing simple features and can this hold both points, lines polygons and more. tween_sf currently has support for (multi)point, (multi)linestring, and (multi)polygon types and requires that the transition is between compatible types (points-to-points, linestring-to-linestring, polygon-to-polygon). For (multi)linestring and (multi)polygon, the behavior is similar to tween_path() and tween_polygon() respectively, with each feature beeing run through the respective function with match = FALSE. For (multi)points it behaves more or less like tweenr::tween_state() except additional points are added as needed to make the to stages contain the same number of points. Points are added on top of existing points so it appears as if the points are divided into more. tween_sf(.data, to, ease, nframes, id = NULL, enter = NULL, exit = NULL) Arguments.data to ease nframes id enter exit A data.frame to start from. If.data is the result of a prior tween, only the last frame will be used for the tween. The new tween will then be added to the prior tween A data.frame to end at. It must contain the same columns as.data (exluding.frame) The easing function to use. Either a single string or one for each column in the data set. The number of frames to calculate for the tween The column to match observations on. If NULL observations will be matched by position. See the

tween_sf 9 Value A data.frame containing intermediary states Examples library(magrittr) star_hole <- poly_star_hole(st = TRUE) circles <- poly_circles(st = TRUE) spiral <- path_spiral(st = TRUE) waves <- path_waves(st = TRUE) random <- point_random(st = TRUE) grid <- point_grid(st = TRUE) df1 <- data.frame(geo = sf::st_sfc(star_hole, spiral, random)) df2 <- data.frame(geo = sf::st_sfc(circles, waves, grid)) tween_sf(df1, df2, 'linear', 30)

Index path_spiral (simple_shapes), 2 path_waves (simple_shapes), 2 point_grid (simple_shapes), 2 point_random (simple_shapes), 2 poly_circle (simple_shapes), 2 poly_circles (simple_shapes), 2 poly_star (simple_shapes), 2 poly_star_hole (simple_shapes), 2 sf::sfc, 8 simple_shapes, 2 st_normalize, 4 transformr (transformr-package), 2 transformr-package, 2 tween_path, 4 tween_path(), 8 tween_polygon, 6 tween_polygon(), 8 tween_sf, 8 tweenr::tween_state(), 4, 6, 8 10