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 |
Function to create coordinates for a Hilbert Curve This functions adds three columns to a data frame: reld, x, y
create_coordinates(df, idcol)
create_coordinates(df, idcol)
df |
the dataframe to use |
idcol |
the column to use for mapping |
a data frame with three additional columns
mtcars %>% tibble::rownames_to_column() %>% create_id_column(rowname) %>% create_coordinates(gghid)
mtcars %>% tibble::rownames_to_column() %>% create_id_column(rowname) %>% create_coordinates(gghid)
Function to create an id column from a character column
create_id_column(df, col)
create_id_column(df, col)
df |
the dataframe that is used |
col |
the column name in NSE format that should be converted |
a dataframe with an additional gghid column
mtcars %>% tibble::rownames_to_column() %>% create_id_column(rowname)
mtcars %>% tibble::rownames_to_column() %>% create_id_column(rowname)
Returns the x/y-position for a distance d in n possible values
d2xy(n, d)
d2xy(n, d)
n |
First value |
d |
Second value |
Vector of x y
Returns the x/y-position for a Vector of distances d in n possible values
d2xy2(n, d)
d2xy2(n, d)
n |
Size of |
d |
Second value |
Matrix of x y values
Function to create the Hilbert Plot
gghilbertplot( df, idcol, color = NULL, size = NULL, label = NULL, alpha = 1, add_curve = FALSE, curve_alpha = 1, curve_color = "black", jitter = 0 )
gghilbertplot( df, idcol, color = NULL, size = NULL, label = NULL, alpha = 1, add_curve = FALSE, curve_alpha = 1, curve_color = "black", jitter = 0 )
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 |
a ggplot object
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)
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
hilbertd2xy(n, d)
hilbertd2xy(n, d)
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) |
Tibble with columns x and y
hilbertd2xy(64,31)
hilbertd2xy(64,31)
Finds the order of the next highest number to the power of 4
order4(n)
order4(n)
n |
number |
Order of next highest number 4^x