Package 'gghilbertstrings'

Title: A Fast 'ggplot2'-Based Implementation of Hilbert Curves
Description: A set of functions that help to create plots based on Hilbert curves. Hilbert curves are used to map one dimensional data into the 2D plane. The package provides a function that generate a 2D coordinate from an integer position. As a specific use case the package provides a function that allows mapping a character column in a data frame into 2D space using 'ggplot2'. This allows visually comparing long lists of URLs, words, genes or other data that has a fixed order and position.
Authors: André Calero Valdez [aut, cre]
Maintainer: AndrĂ© Calero Valdez <[email protected]>
License: MIT + file LICENSE
Version: 0.3.3
Built: 2025-03-06 04:03:30 UTC
Source: https://github.com/sumidu/gghilbertstrings

Help Index


Function to create coordinates for a Hilbert Curve This functions adds three columns to a data frame: reld, x, y

Description

Function to create coordinates for a Hilbert Curve This functions adds three columns to a data frame: reld, x, y

Usage

create_coordinates(df, idcol)

Arguments

df

the dataframe to use

idcol

the column to use for mapping

Value

a data frame with three additional columns

Examples

mtcars %>% tibble::rownames_to_column() %>% create_id_column(rowname) %>% create_coordinates(gghid)

Function to create an id column from a character column

Description

Function to create an id column from a character column

Usage

create_id_column(df, col)

Arguments

df

the dataframe that is used

col

the column name in NSE format that should be converted

Value

a dataframe with an additional gghid column

Examples

mtcars %>% tibble::rownames_to_column() %>% create_id_column(rowname)

Returns the x/y-position for a distance d in n possible values

Description

Returns the x/y-position for a distance d in n possible values

Usage

d2xy(n, d)

Arguments

n

First value

d

Second value

Value

Vector of x y


Returns the x/y-position for a Vector of distances d in n possible values

Description

Returns the x/y-position for a Vector of distances d in n possible values

Usage

d2xy2(n, d)

Arguments

n

Size of

d

Second value

Value

Matrix of x y values


Function to create the Hilbert Plot

Description

Function to create the Hilbert Plot

Usage

gghilbertplot(
  df,
  idcol,
  color = NULL,
  size = NULL,
  label = NULL,
  alpha = 1,
  add_curve = FALSE,
  curve_alpha = 1,
  curve_color = "black",
  jitter = 0
)

Arguments

df

Data frame to generate plot from

idcol

The column name to be used for mapping (gghid)

color

The column to map to color

size

The column to map to size

label

The column that contains the label

alpha

The amount of alpha blending for the individual points

add_curve

Whether or not to add the underlying hilbert curve

curve_alpha

The amount of alpha blending for the hilbert curve

curve_color

The color of the hilbert curve

jitter

The amount of jitter to add to prevent overplotting

Value

a ggplot object

Examples

tibble::tibble(val = 1:128, size = runif(128, 1, 5), color = rep(c(1,2,3,4),32)) %>%
        gghilbertplot(val, color = factor(color), size = size, add_curve = TRUE)

Hilbert conversion, distance to coordinates

Description

Hilbert conversion, distance to coordinates

Usage

hilbertd2xy(n, d)

Arguments

n

Size (must be a 2^k value, such as 4,8,16,32)

d

A vector of values to be converted to coordinates (starts with 0)

Value

Tibble with columns x and y

Examples

hilbertd2xy(64,31)

Finds the order of the next highest number to the power of 4

Description

Finds the order of the next highest number to the power of 4

Usage

order4(n)

Arguments

n

number

Value

Order of next highest number 4^x