Skip to contents

Wrap periodic data to an arbitrary range

Usage

wrap(object, ...)

# S3 method for periodic_df
wrap(object, ..., .group = NULL)

Arguments

object

a periodic data frame

...

name-value pairs of expressions defining range specifications

.group

optional group column (see examples)

Value

An object of the same class as object but with no periodic subclass or periodicity specifications and wrapped dimensions.

Examples


x <- seq(0, 360 - 20, by = 20)
df <- data.frame(x = x, y = cos(x*pi/180))
df_p <- periodic(df, x = c(0, 360))

# wrap in default rante
df_wrapped <- wrap(df_p)
range(df_wrapped$x)
#> [1]   0 360
range(df$x)
#> [1]   0 340

# specify range
df_wrapped <- wrap(df_p, x = c(-145, 365))
range(df_wrapped$x)
#> [1] -140  360

# with non regular intervals
x <- runif(30, 0, 360)
df <- periodic(data.frame(x = x, y = cos(x*pi/180)),
               x = c(0, 360))
df_wrapped <- wrap(df, x = c(-180, 540))
range(df_wrapped$x)
#> [1] -174.4090  537.7801
range(df$x)
#> [1]  20.40561 358.31598
if (FALSE) {
# This example illustrates the use of the .group parameter
library(ggplot2)
map <- periodic(map_data("world"), long = long)

# If wrapped without .group, the repated parts of the map
# have the same group and so polygons are not correctly defined.
map_wrapped <- wrap(map, long = c(-180, 360))
ggplot(map_wrapped, aes(long, lat, group = group)) +
    geom_path()

# Using groups, you get the correct grouping.
map_wrapped <- wrap(map, long = c(-180, 360), .group = group)
ggplot(map_wrapped, aes(long, lat, group = group)) +
    geom_path()
}