| Title: | Easy Plotting of Periodic Data with 'ggplot2' |
|---|---|
| Description: | Implements methods to plot periodic data in any arbitrary range on the fly. |
| Authors: | Elio Campitelli [cre, aut] (ORCID: <https://orcid.org/0000-0002-7742-9230>) |
| Maintainer: | Elio Campitelli <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.4 |
| Built: | 2026-07-02 21:27:21 UTC |
| Source: | https://github.com/cran/ggperiodic |
Get period information from an object
get_period(object)get_period(object)
object |
a periodic object |
Implements methods to plot periodic data in any arbitrary range on the fly.
The only thing you need to do is add the periodic information to a
data frame with periodic(). You then can manually wrap your data around any
domain with wrap() or just let ggplot2 do it automatically for you
Maintainer: Elio Campitelli [email protected] (ORCID)
Authors:
Elio Campitelli [email protected] (ORCID)
Useful links:
Check if an object is periodic
is.periodic(object)is.periodic(object)
object |
an object |
Creates a periodic object by specifying the periodic variables and their periods.
periodic(object, ...) ## Default S3 method: periodic(object, period, ...) ## S3 method for class 'data.frame' periodic(object, ...) setperiodic(object, ...)periodic(object, ...) ## Default S3 method: periodic(object, period, ...) ## S3 method for class 'data.frame' periodic(object, ...) setperiodic(object, ...)
object |
the object to coerce to periodic |
... |
name-value pairs of expressions defining the period |
period |
a numeric vector whose range defines the period |
An object of subclass periodic_df or periodic_v.
If object is of class data.table, then it will modify the object by
reference. To modify this behaviour, use
options(ggperiodic.data.table.copy = TRUE). setperiodic() will modify a
data.table by reference bypassing the global option.
library(ggplot2) 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)) ggplot(df_p, aes(x, y)) + geom_line() + # periodic data geom_point(data = df) # non periodic data # Extend domain ggplot(df_p, aes(x, y), x = c(-180, 540)) + geom_line() + geom_point(data = df) # with non regular intervals x <- runif(30, 0, 360) df <- periodic(data.frame(x = x, y = cos(x*pi/180)), x = c(0, 360)) ggplot(df, aes(x, y), x = c(-180, 540)) + geom_point()library(ggplot2) 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)) ggplot(df_p, aes(x, y)) + geom_line() + # periodic data geom_point(data = df) # non periodic data # Extend domain ggplot(df_p, aes(x, y), x = c(-180, 540)) + geom_line() + geom_point(data = df) # with non regular intervals x <- runif(30, 0, 360) df <- periodic(data.frame(x = x, y = cos(x*pi/180)), x = c(0, 360)) ggplot(df, aes(x, y), x = c(-180, 540)) + geom_point()
Wraps periodic data from one specified range to the other in one line.
qwrap(object, ..., .group = NULL)qwrap(object, ..., .group = NULL)
object |
the object to wrap |
... |
named formulas with the form |
.group |
optional group column (see wrap) |
qwrap is a shortcut to wrap(periodic(obejct, x = range_from), x = range_to)
x <- seq(0, 360 - 20, by = 20) df <- data.frame(x = x, y = cos(x*pi/180)) qwrap(df, x = c(0, 360) ~ c(-180, 180))x <- seq(0, 360 - 20, by = 20) df <- data.frame(x = x, y = cos(x*pi/180)) qwrap(df, x = c(0, 360) ~ c(-180, 180))
Remove periodic specifications
unperiodic(object, ...) setunperiodic(object, ...)unperiodic(object, ...) setunperiodic(object, ...)
object |
the object to remove periodicities |
... |
arguments to methods |
An object of the same class as object but with no periodic subclass or
periodicity specifications.
If object is of class data.table, then it will modify the object by
reference. To modify this behaviour, use
options(ggperiodic.data.table.copy = TRUE). setperiodic() will modify a
data.table by reference bypassing the global option.
Wrap periodic data to an arbitrary range
wrap(object, ...) ## S3 method for class 'periodic_df' wrap(object, ..., .group = NULL)wrap(object, ...) ## S3 method for class 'periodic_df' wrap(object, ..., .group = NULL)
object |
a periodic data frame |
... |
name-value pairs of expressions defining range specifications |
.group |
optional group column (see examples) |
An object of the same class as object but with no periodic subclass or
periodicity specifications and wrapped dimensions.
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) range(df$x) # specify range df_wrapped <- wrap(df_p, x = c(-145, 365)) range(df_wrapped$x) # 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) range(df$x) ## Not run: # 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() ## End(Not run)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) range(df$x) # specify range df_wrapped <- wrap(df_p, x = c(-145, 365)) range(df_wrapped$x) # 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) range(df$x) ## Not run: # 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() ## End(Not run)