Learn R Programming

crqa (version 2.0.6)

plot_rp: Plot a recurrence matrix

Description

Given a recurrence plot object (RP) returned from the function crqa(), visualize it.

Usage

plot_rp(rp_matrix,
        title = "",
        xlabel = "Time",
        ylabel = "Time",
        pcolour = "black",
        geom = c("tile", "point", "void"),
        flip_y = FALSE)

Value

A ggplot2 plot.

Arguments

rp_matrix

A recurrence plot sparse matrix from crqa()

title

Main title of the plot (character). Default: "" (empty)

xlabel

The x-axis label (character). Default: "Time"

ylabel

The y-axis label (character). Default: "Time"

pcolour

The colour used for points in the plot (character). Default: "black"

geom

The ggplot2 geom used to draw the points (character). One of: "tile", "point" or "void". The default value, "tile", uses (geom_tile() to plot the points. The value "point" uses geom_point() to plot the points, and the value "void" produces a plot without any geom, so users can add their own for a more costumized plot (see examples below).

flip_y

Logical argument controlling whether to flip the directionality of the y axis (logical). Default: FALSE

Author

Mønster, D. danm@econ.au.dk

Details

The argument geom is a character denoting what type of ggplot2 geom is used to plot the points in the recurrence plot. Allowed values are "tile", "point" and "void". The latter produces an empty plot, so the user is required to add their own geom to the output. See example below.

See Also

This plotting solution as substituted what was previously plotRP() available till version crqa.2.0.5

Examples

Run this code
# Here is a very short example based on these two time series
ts_1 <-  c(0, 0, 1, 1, 0, 0, 2, 2, 1, 1)
ts_2 <-  c(1, 1, 2, 2, 0, 0, 1, 2, 2, 1)

# Create the cross recurrence matrix
short_rec <-  crqa(ts_1, ts_2, 
                   delay = 1, embed = 1, radius = 0.001,
                   rescale = 1, method = "crqa")

# Extract the cross recurrence matrix
small_rp <-  short_rec$RP

# Make a cross recurrence plot with blue tiles
plot_rp(small_rp, pcolour  = "blue", geom = "tile")

# Make a cross recurrenbce plot with blue points
plot_rp(small_rp, pcolour  = "blue", geom = "point")

## Uncomment below if you want to have more example. Not runnable because
## of CRAN, globally unavailable function plus timing constraint to check vignette.

# Neither of the two plots above may be suitable
# Using geom = "void" we can add a custumized geom, here blue tiles
# that are smaller than the default width and height
# plot_rp(small_rp, geom = "void") +
#  geom_tile(fill = "blue", height = 0.75, width = 0.75)

# Another custom geom uses tiles with a border colour
# plot_rp(small_rp, geom = "void") +
#  geom_tile(fill = "blue", colour = "pink", linewidth = 1)

# Use the eyemovement dataset to create a cross-recurrence plot
# large_crqa <- crqa(eyemovement$narrator, eyemovement$listener,
#                delay = 1, embed = 1, radius = 0.001,
#                method = "crqa", metric = "euclidean", datatype = "continuous")

# Extract the recurrence matrix from the result
# large_rp <- large_crqa$RP

# Create a recurrence plot using defaults
# plot_rp(large_rp)

# The same recurrence plot with flipped y axis and using geom_point()
# plot_rp(large_rp, flip_y = TRUE, geom = "point", title = "Flipped y axis") 

# Add axes labels, a title and extra plot elements
# Note that we can add to the output, here added the line of synchonization
# using ggplot2's geom_abline() function.
# plot_rp(large_rp, 
#        xlabel = "Narrator",
#        ylabel = "Listener",
#        title = "Coloured tiles with line of synchronization",
#        pcolour = "blue") +
#  geom_abline(intercept = 0, slope = 1)

Run the code above in your browser using DataLab