### 2. Zenplots ################################################################ library("zenplots") data("olive", package = "zenplots") zenplot(olive) zenplot(olive, plot1d = "layout", plot2d = "layout") str(zenplot) ### 2.1. Layout ################################################################ ## Zigzagging layout methods olive2 <- cbind(olive, olive) zenplot(olive2, n2dcols = 6, plot1d = "layout", plot2d = "layout", method = "single.zigzag") zenplot(olive2, n2dcols = 6, plot1d = "layout", plot2d = "layout", method = "double.zigzag") zenplot(olive2, n2dcols = 6, plot1d = "layout", plot2d = "layout", method = "tidy") ## Spacings between 1d or 2d plots and around whole zenplots zenplot(olive, plot1d = "layout", plot2d = "layout", method = "double.zigzag", last1d = FALSE, ispace = 0.1) zenplot(olive, plot1d = "layout", plot2d = "layout", n2dcol = 4, n2dplots = 8, width1d = 2, width2d = 4) ### 3. Zenpaths ################################################################ (path <- 1:5) zenpath(5) # zenplot(x = dataMat[, path]) # dataMat() is a hypothetical object (does not exist; see paper) str(zenpath) zenpath(5, method = "front.loaded") zenpath(5, method = "back.loaded") zenpath(5, method = "balanced") zenpath(c(3,5), method = "eulerian.cross") oliveAcids <- olive[, !names(olive) %in% c("area", "region")] zpath <- zenpath(ncol(oliveAcids)) zenplot(oliveAcids[, zpath], plot1d = "hist", plot2d = "density") ### 4. Build your own zenplots ################################################# ### 4.1. Custom plot functions ################################################# zenplot(oliveAcids, plot1d = "hist", plot2d = "density", pkg = "graphics") zenplot(oliveAcids, plot1d = hist_1d_graphics, plot2d = density_2d_graphics, pkg = "graphics") ### 4.3. Custom layout and plots -- a spiral of ggplots example ################ path <- c(1,2,3,1,4,2,5,1,6,2,7,1,8,2,3,4,5,3,6,4,7,3,8,4,5,6,7,5,8,6,7,8) turns <- c("l", "d","d","r","r","d","d","r","r","u","u","r","r","u","u","r","r", "u","u","l","l","u","u","l","l","u","u","l","l","d","d","l","l", "u","u","l","l","d","d","l","l","d","d","l","l","d","d","r","r", "d","d","r","r","d","d","r","r","d","d","r","r","d","d") library("ggplot2") stopifnot(packageVersion("ggplot2") >= "2.2.1") ggplot2d <- function(zargs) { r <- extract_2d(zargs) num2d <- zargs$num/2 df <- data.frame(x = unlist(r$x), y = unlist(r$y)) p <- ggplot() + geom_point(data = df, aes(x = x, y = y), cex = 0.1) + theme(axis.line = element_blank(), axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank()) if (num2d == 1) p <- p + theme(panel.background = element_rect(fill = 'royalblue3')) if (num2d == (length(zargs$turns)-1)/2) p <- p + theme(panel.background = element_rect(fill = 'maroon3')) ggplot_gtable(ggplot_build(p)) } zenplot(oliveAcids[,path], turns = turns, pkg = "grid", plot2d = function(zargs) ggplot2d(zargs)) ### 4.4. Data groups ########################################################### oliveAcids.by.area <- split(oliveAcids, f = olive$area) names(oliveAcids.by.area)[3] <- gsub("\\.", " ", names(oliveAcids.by.area)[3]) names(oliveAcids.by.area) zenplot(oliveAcids.by.area, labs = list(group = NULL)) zenplot(oliveAcids.by.area, lim = "groupwise", labs = list(sep = " - "), plot1d = function(zargs) label_1d_graphics(zargs, cex = 0.8), plot2d = function(zargs) points_2d_graphics(zargs, group... = list(sep = "\n - \n"))) ### 4.5. Custom zenpaths ####################################################### library("scagnostics") Y <- scagnostics(oliveAcids) X <- Y["Convex", ] d <- ncol(oliveAcids) M <- matrix(, nrow = d, ncol = d) M[upper.tri(M)] <- X M[lower.tri(M)] <- t(M)[lower.tri(M)] round(M, 5) zpath <- zenpath(M, method = "strictly.weighted") head(M[do.call(rbind, zpath)]) (ezpath <- extract_pairs(zpath, n = c(6, 0))) library("graph") plot(graph_pairs(ezpath)) (cezpath <- connect_pairs(ezpath)) oliveAcids.grouped <- groupData(oliveAcids, indices = cezpath) zenplot(oliveAcids.grouped) ### 5. Advanced features ####################################################### ### 5.1. The structure of a zenplot ############################################ res <- zenplot(olive, plot1d = "layout", plot2d = "layout", draw = FALSE) str(res) res[["path"]][["occupancy"]] head(res[["path"]][["positions"]]) ### 5.2. Tools for writing 1d and 2d plot functions ############################ ## Bursting the data and extracting the current plot variables points_2d_graphics ## Setting up the plot region and determining the plot indices plot_region plot_indices ## Unfolding the cube n2dcols <- ncol(olive) - 1 stopifnot(identical(res, unfold(nfaces = n2dcols)))