make_glyphs: Make glyphs

Description Usage Arguments Value Author(s) Examples

View source: R/make_glyphs.R

Description

Given various forms of multidimensional data and a function of data vectors to colors, make a corresponding list of glyphs in png format or a class of pixmap. The colors in each glyph is placed in the order of Hilbert curve, Morton curve or a method provided by Keim which is better used when the data has some inherent structure such as time series. By default, the data2col function is given, and one can adjust it by the parameters given (see data2col), or one can provide his own function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
make_glyphs(
  data,
  glyph_type = c("Hilbert", "Morton", "rectangle"),
  width,
  height,
  cols = NULL,
  hueRange = c(0, 360),
  intensityRange = c(0.4, 1),
  alpha = 1,
  numCols = 1e+05,
  maxColorValue = 255,
  xLow = NULL,
  origin = NULL,
  xHigh = NULL,
  missingCol = NULL,
  outRangeCol = NULL,
  data2colfn,
  type = c("png", "pixmap"),
  byrow = TRUE,
  ...
)

Arguments

data

a data frame, matrix, where each row or column is for an individual, it can also be a list of data vectors for each individual

glyph_type

if "Hilbert"(Default) colors in each glyph is placed in the order of Hilbert curve, if "Morton", it is in Morton curve, and if "rectangle" it is the recursive rectangular method provided by Keim.

width

vector of width in each level of algorithm provided by Keim, must be given if glyph_type is "rectangle"

height

vector of height in each level of algorithm provided by Keim if glyph_typbe is "rectangle"

cols

a vector of rgb colours or NULL (default). If NULL, cols is constructed from hueRange, intensityRange, alpha, numCols, and maxColorValue.

hueRange

numeric vectors with values in [0, 360], it specifies the hue range. It does not need to be in ascending order since it is only used in the linear interpolation

intensityRange

numeric vectors with values in [0, 1], it specifies the intersity range. It does not need to be in ascending order since it is used in the linear interpolation

alpha

number in [0,1]. It specifies the alpha transparency value.

numCols

number. It specifies the number of colors used to do the mapping, and the higher the value is, the more distinguished between different data values.

maxColorValue

number in (0, 255] giving the maximum of the color values range.

xLow

lower value of one's interested range

origin

middle value in one's interested range in (xLow, xHigh), which specifies the data value mapping to the center of color scale, or "mean", "median" can be specified to set the origin as the mean or median value for each glyph

xHigh

higher value of one's interested range

missingCol

color character specifying the color for the missing data. It is in the form of "#rrggbbaa", and the default is yellow.

outRangeCol

color characters specifying the color for the data outside our interested range. If the length is two, the first will specify the color for the data lower than the range, and the second is for higher. the color should have the same form with missingCol, and the default is "blue" and "red".

data2colfn

function mapping from data values to color values, if missing, the function will be data2col

type

string specifying the format of output. "png" means the output is a list of data matrices in the png format, and "pixmap" means the output is a list of class of pixmaps.

byrow

logical value. If TRUE each row in the data frame or matrix will be considered as an individual. Otherwise, each column will be an individual.

...

Arguments passed to data2colfn

Value

a list of data matrices of png format or a list of pixmaps

Author(s)

Jiahua Liu, Wayne Oldford

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
library(qrmdata)
data("SP500_const") # load the constituents data from qrmdata
time <- c("2007-01-03", "2009-12-31") # specify time period
x <- SP500_const[paste0(time, collapse = "/"),] # grab out data
data_c <- list() # complete data
for (i in 1:ncol(x)){
  data_c[[i]] <- x[,i]
}
x <- t(na.omit(t(x)))
data <- split(x,col(x)) # omit the missing data

Glyphs <- make_glyphs(data[1:24]) # list of glyphs in the png format
Glyphs <- make_glyphs(data_c[1:24], glyph_type = "Morton")
width=c(1,6,1,12,1)
height=c(1,1,4,1,3)
Glyphs <- make_glyphs(data_c[1:24], width = width, height = height, glyph_type = "rectangle", alpha = 0.7)
Glyphs_pixmap <- make_glyphs(data_c[1:24], glyph_type = "Morton", type = "pixmap", intensityRange = c(1,0.4))

# list of png format plot
sideLength <- ceiling(sqrt(length(Glyphs)))
plot(0,type='n', xlim=c(0, sideLength), ylim=c(0,sideLength),axes = FALSE,xlab = "", ylab = "")
glyph_x <- 0.7
glyph_y <- 0.5
plot <- Map(function(Glyphs_i,i){
  rasterImage(Glyphs_i,(i-1)%%sideLength, sideLength-1-(i-1)%/%sideLength, (i-1)%%sideLength+glyph_x, sideLength-(1-glyph_y)-(i-1)%/%sideLength)
}, Glyphs,1:length(Glyphs))

# list of class of pixmap plot
sideLength <- ceiling(sqrt(length(Glyphs)))
glyph_x <- 0.7
glyph_y <- 0.5
plot(0,type='n', xlim=c(0, sideLength), ylim=c(0,sideLength),axes = FALSE,xlab = "", ylab = "")
plot <- Map(function(Glyphs_i,i){
  addlogo(Glyphs_i, px=c((i-1)%%sideLength, (i-1)%%sideLength+glyph_x), py=c(sideLength-1-(i-1)%/%sideLength, sideLength-(1-glyph_y)-(i-1)%/%sideLength))
},Glyphs_pixmap, 1:length(Glyphs_pixmap))

rwoldford/glyphs documentation built on Nov. 14, 2020, 2:29 a.m.