LSD/0000755000176200001440000000000013672363532010706 5ustar liggesusersLSD/NAMESPACE0000644000176200001440000000266213672360025012125 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(LSD.pie) export(align) export(clusterplot) export(colorpalette) export(comparisonplot) export(complementarycolor) export(convertcolor) export(convertgrey) export(daltonize) export(demotour) export(disco) export(distinctcolors) export(ellipsescatter) export(emptyplot) export(fusionplot) export(heatbarplot) export(heatboxplot) export(heathist) export(heatpairs) export(heatscatter) export(heatscatterpoints) export(intersphere) export(linesplot) export(makemovie) export(msdplot) export(plotit) export(plotmatrix) export(singleclusterplot) export(singlefusionplot) export(singlemsdplot) export(webdesign) export(windowxy) importFrom("grDevices", "bmp", "cm.colors", "col2rgb", "colorRampPalette", "dev.new", "dev.off", "devAskNewPage", "heat.colors", "hsv", "jpeg", "pdf", "png", "postscript", "rainbow", "rgb", "terrain.colors", "tiff", "topo.colors") importFrom("graphics", "abline", "arrows", "axis", "barplot", "box", "boxplot", "clip", "contour", "hist", "layout", "legend", "lines", "mtext", "pairs", "par", "plot.new", "plot.window", "points", "polygon", "rect", "rug", "segments", "text", "title") importFrom("stats", "approxfun", "cor", "density", "dnorm", "kmeans", "median", "qchisq", "quantile", "rf", "rnorm", "runif", "sd", "splinefun", "var") importFrom("utils", "combn") LSD/data/0000755000176200001440000000000012453455317011616 5ustar liggesusersLSD/data/homer.RData0000755000176200001440000000051612012456660013643 0ustar liggesusersݘK @ Ǫ]z/`U/ {1$i?LǴ2ivUvN63kvyΖƞr;#ˍrÍrPn'ѸWB ^ ;w=f|z!o6dC}u2팈*Nʜ+"dBK.f̡ rBaJt{͠>LSD/man/0000755000176200001440000000000013672132651011455 5ustar liggesusersLSD/man/webdesign.Rd0000755000176200001440000000217413672352362013725 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.utilities.R \name{webdesign} \alias{webdesign} \alias{LSD.webdesign} \title{Colored rectangular grid} \usage{ webdesign(xlim, ylim, colpal = "rdbu", xlabels = NULL, ylabels = NULL, ...) } \arguments{ \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{xlabels}{a character vector containing labels depicted parallel to the x-axis.} \item{ylabels}{a character vector containing labels depicted parallel to the y-axis.} \item{...}{additional parameters to be passed to abline().} } \description{ Adds a colored rectangular grid to an existing plot. } \examples{ emptyplot(c(-5,5),c(-5,5)) labels = c("2 fold","4 fold","8 fold") webdesign(c(-5,5),c(-5,5),lty = 2,xlabels = labels,ylabels = labels) } \seealso{ \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{grid} \keyword{web} LSD/man/LSD.pie.Rd0000755000176200001440000000673213672347441013162 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.pie.R \name{LSD.pie} \alias{LSD.pie} \title{Custom-built piechart version} \usage{ LSD.pie( props, x = 0, y = 0, radius = 1, colpal = "prgn", simulate = FALSE, daltonize = FALSE, cvd = "p", edges = 1000, add = FALSE, xlim = c(-1, 1), ylim = c(-1, 1), main = "LSD.pie: piecharts", alpha = NULL, addPercent = FALSE, textcol = "black", clockwise = FALSE, init.angle = 0, labels = c(), cex = 1, cex.percentage = cex, border = NA, ... ) } \arguments{ \item{props}{a numeric vector giving the relations of the pie pieces (need not to be normalized).} \item{x}{x-position of the piechart.} \item{y}{y-position of the piechart.} \item{radius}{a numeric value giving the radius of the piechart.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{edges}{an integer giving the number of edges the "circle" will have.} \item{add}{logical: if \code{TRUE} (\code{FALSE} by default), the pie is added to an existing plot.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{addPercent}{logical: if \code{TRUE} (\code{FALSE} by default), the percentage of each slice is written inside of the pie.} \item{textcol}{a R build-in color for the percentages of \code{addPercent}.} \item{clockwise}{if \code{TRUE} (\code{FALSE} by default), slices drawn clockwise (counter clockwise, if \code{FALSE}).} \item{init.angle}{a numerical value representing an angle as a starting angle for the drawn slices.} \item{labels}{a character vector giving the names for the pie slices.} \item{cex}{scaling a numeric value giving the expansion factor for the slice names (if labels are given).} \item{cex.percentage}{a numeric value giving the expansion factor for the percentage values (if \code{addPercent = TRUE}).} \item{border}{a R build-in color giving the border color (NA by default).} \item{...}{additional parameters to be passed to points and plot.} } \description{ Piecharts at arbitrary position and radii. } \examples{ emptyplot(xlim=c(1,9),ylim=c(1,9)) mtext(paste("LSD.pie: piecharts"),3,2,cex=1.25) polygon(c(4,2,4,7,8),c(4,8,4,2,8)) LSD.pie(sample(1:50,5),4,4,add=TRUE,radius=2,colpal="prgn",alpha=75) LSD.pie(sample(1:50,5),2,8,add=TRUE,colpal="prgn",alpha=75) LSD.pie(sample(1:50,5),8,8,add=TRUE,colpal="prgn",alpha=75) LSD.pie(sample(1:50,5),7,2,add=TRUE,colpal="prgn",alpha=75) } \seealso{ \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb, Carina Demel } \keyword{pie} LSD/man/intersphere.Rd0000755000176200001440000000354413672347441014312 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.intersphere.R \name{intersphere} \alias{intersphere} \alias{LSD.intersphere} \title{Intersphere: a fancy Venn diagram} \usage{ intersphere( data, colors = NULL, alpha = 25, cex = 1, expand.circles = 1, expand.lims = 1.5, main = "intersphere: overlap diagram", onlySets = seq(length(data), 2, by = -1) ) } \arguments{ \item{data}{a list with n entries having elements that can be represented as sets (have union and intersect methods).} \item{colors}{a character vector of R build-in colors for circles representing different sets.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{cex}{a numeric value giving the character expansion factor for intersect size text inside each circle.} \item{expand.circles}{a numeric value giving the expansion factor of circles (multiplicative).} \item{expand.lims}{a numeric value giving the expansion of x and y limits (additive).} \item{main}{title(s) of the plot, standard graphics parameter.} \item{onlySets}{vectors, which n-overlaps should be shown, default to all 1 < n < length(data).} } \description{ Create circles for visualizing overlaps between up to 4 datasets. } \examples{ data = list( "A" = sample(1:200,100), "B" = sample(1:200,150), "C" = sample(1:200,50)) intersphere(data,colors = c("orange","skyblue","green")) data = list( "A" = sample(1:200,100), "B" = sample(1:200,150), "C" = sample(1:200,50), "D" = sample(1:200,75)) colors = c("orange","skyblue","green","purple") intersphere(data,colors,expand.circles = 0.5,expand.lims = 0.5) } \seealso{ \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Sebastian Duemcke, Bjoern Schwalb } \keyword{Venn} \keyword{intersphere} LSD/man/plotit.Rd0000755000176200001440000000531313672360011013255 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.plotit.r \name{plotit} \alias{plotit} \alias{LSD.plotit} \title{Plotting wrapper function to plot plots in printable quality and all kinds of formats} \usage{ plotit( filename, sw = 1, sh = 1, sres = 1, plotsfkt, ww = 7, wh = 7, pointsize = 12, dev.pointsize = 8, paper = "special", quality = 100, units = "px", bg = "white", fileformat = "jpeg", saveit = FALSE, notinR = FALSE, addformat = NULL ) } \arguments{ \item{filename}{name of the plot to be saved with the format type suffix.} \item{sw}{scaling factor of weight.} \item{sh}{scaling factor of height.} \item{sres}{scaling factor of the resolution.} \item{plotsfkt}{list of plots to be plotted.} \item{ww}{width of window.} \item{wh}{height of window.} \item{pointsize}{the default pointsize of plotted text, interpreted as big points (1/72 inch) for plots to be saved.} \item{dev.pointsize}{pointsize of plotted text, interpreted as big points (1/72 inch) for display in R.} \item{paper}{needed only if filformat = "pdf" or "ps".} \item{quality}{needed only if filformat = "jpeg".} \item{units}{needed only if filformat = "jpeg", "png", "bmp" or "tiff".} \item{bg}{backgroundcolor.} \item{fileformat}{save the plot as "pdf", "ps", "jpeg", "png", "bmp" or "tiff".} \item{saveit}{should plot be saved.} \item{notinR}{should plot be not plotted in R.} \item{addformat}{should plot be saved additionally in another format ("pdf", "ps", "jpeg", "png", "bmp" or "tiff").} } \description{ Plotting wrapper function to save plots in R as "pdf", "ps", "jpeg", "png", "bmp" or "tiff". } \examples{ data(homer) plotsfkt = function(){ colpal = c("white","black","yellow","wheat3") align(homer,colpal = colpal,main = "D'OH!",asp = 1,axes = FALSE) } # choose 'saveit = TRUE' for saving the plot in the specified fileformat # # choose 'notinR = TRUE' to suppress plotting in R # plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "jpeg") plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "png") plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "bmp") plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "tiff") plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "ps") plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "pdf") } \seealso{ \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{bmp} \keyword{jpeg} \keyword{pdf} \keyword{plot} \keyword{png} \keyword{ps} \keyword{tiff} LSD/man/msdplot.Rd0000755000176200001440000000532113672347441013437 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.msdplot.r \name{msdplot} \alias{msdplot} \alias{LSD.msdplot} \title{Visualize two-dimensional data clusters} \usage{ msdplot( input, label = NULL, at = NULL, xlim = NULL, ylim = NULL, xlab = "", ylab = "", main = "msdplot", xaxt = "s", xlabels = NULL, las = 1, separate = TRUE, size = TRUE, col = "darkgreen", bars = TRUE, alpha = 50, ... ) } \arguments{ \item{input}{matrix or list with numerical entries, quantiles of cols will define lines.} \item{label}{a character vector assigning rows/elements of 'input' to clusters (if specified, multiple clusters can be depicted in different colors and/or subsequent plots).} \item{at}{a integer vector containing the x-positions corresponding to the columns of 'input'.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{xlab}{x labels, standard graphics parameter.} \item{ylab}{y labels, standard graphics parameter.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{xaxt}{a character which specifies the x axis type ("n" suppresses plotting of the axis).} \item{xlabels}{a character vector containing labels for the x-axis.} \item{las}{las=1: horizontal text, las=2: vertical text (x-axis labels).} \item{separate}{if \code{TRUE} (by default), different clusters are depicted in subsequent plots.} \item{size}{logical: if \code{TRUE} (by default), the size of each cluster is added to the title of the respective plot.} \item{col}{a character vector giving R build-in colors for different clusters.} \item{bars}{logical: if \code{TRUE} (by default), error bars are added at each position.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{...}{additional parameters to be passed to points and plot.} } \description{ Depict a numeric matrix or list utilizing the underlying mean and standard deviation estimates of one dimension in a color encoded fashion. } \examples{ at = c(2,4,8,16,32) clus = matrix(rnorm(500,sd=0.5),ncol=5) batch = sample(c(-8,-6,-4,-2),100,replace=TRUE) clus = clus + cbind(0,0.25*batch,0.5*batch,0.75*batch,batch) clus = clus - clus[,1] clus = t(t(clus)*c(0,0.1,0.25,0.5,1)) labs = paste("cluster",kmeans(clus,4)$cluster) colpal = c("darkgreen","darkblue","darkred","black") msdplot(clus,labs,at,separate=FALSE,col=colpal,alpha=25,xlabels=at) msdplot(clus,labs,at,col=colpal,alpha=50,xlabels=at) } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{mean} \keyword{sd} LSD/man/demotour.Rd0000755000176200001440000000103013672347441013604 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.demotour.R \name{demotour} \alias{demotour} \alias{LSD.demotour} \title{LSD teaser} \usage{ demotour() } \description{ A compilation of selected plot examples. } \examples{ demotour() } \seealso{ \code{\link{heatscatter}}, \code{\link{clusterplot}}, \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{daltonize}} } \author{ Bjoern Schwalb } \keyword{clusterplot} \keyword{colorpalette} \keyword{daltonize} \keyword{disco} \keyword{heatscatter} LSD/man/heatpairs.Rd0000755000176200001440000001070113672347441013733 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.heatscatter.R \name{heatpairs} \alias{heatpairs} \alias{LSD.heatpairs} \title{Pairwise colored scatterplot based on a two-dimensional Kernel Density Estimation} \usage{ heatpairs( mat, main = "heatpairs", xlim = NULL, ylim = NULL, labels = NULL, add.points = FALSE, group = NULL, color.group = "magenta", method = "spearman", colpal = "heat", simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, rev = FALSE, pch = 19, cexplot = 0.5, cor.cex = 2.5, nrcol = 30, grid = 100, only = "none", add.contour = FALSE, nlevels = 10, color.contour = "black", greyscale = FALSE, log = "", ... ) } \arguments{ \item{mat}{a matrix with numerical entries.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{labels}{a character vector giving the labels to be shown on the diagonal.} \item{add.points}{logical: if \code{TRUE} (\code{FALSE} by default), a certain 'group' of points can be colored in all pairwise plots.} \item{group}{indices or rownames of 'mat' to be highlighted in all pairwise plots (not necessarily all).} \item{color.group}{R build-in color in which the 'group' of points should be highlighted.} \item{method}{a character specifying the correlation method to use ('spearman' (default), 'pearson' or 'kendall').} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{pch}{plotting 'character'. This can either be a single character or an integer code for one of a set of graphics symbols. (see '?pch', to be passed to plot).} \item{cexplot}{a numerical value giving the amount by which the points should be magnified relative to the default.} \item{cor.cex}{a numerical value giving the amount by which the correlation characters should be magnified relative to the default.} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} \item{grid}{an integer specifying the size of the grid used for the KDE.} \item{only}{a character string which contains 'x' if the density should only be computed for the x axis, 'y' for the y axis (defaults to 'none' for the two-dimensional case).} \item{add.contour}{logical: if \code{TRUE} (\code{FALSE} by default), the contour lines are added to the plot.} \item{nlevels}{an integer giving the number of levels of the contour lines.} \item{color.contour}{R build-in color for the contour lines.} \item{greyscale}{logical: if \code{TRUE} (\code{FALSE} by default), the used colorpalette is converted to greyscales.} \item{log}{a character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic.} \item{...}{additional parameters to be passed to points and plot} } \description{ Pairwise visualization of two dimensional data in a three dimensional fashion facilitating a color encoded Kernel Density Estimation. } \examples{ points = 10^4 x = rnorm(points/2) x = c(x,x+2.5) y = x + rnorm(points,sd=0.75) x = sign(x)*abs(x)^1.3 mat = cbind(x,y,x + rnorm(points,sd=0.5)) colnames(mat) = c("x","y","z") rownames(mat) = 1:nrow(mat) heatpairs(mat,labels=c(expression(Xi),expression(Lambda),expression(Delta))) } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{heatcolors} \keyword{scatterplot} LSD/man/makemovie.Rd0000755000176200001440000000245013672347441013732 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.makemovie.R \name{makemovie} \alias{makemovie} \alias{LSD.makemovie} \title{Interpolate rows of a matrix to extend the number of cols} \usage{ makemovie(input, timepoints = NULL, timestep = 1, motionline = NULL) } \arguments{ \item{input}{a matrix with numerical entries.} \item{timepoints}{a integer vector containing the timepoints corresponding to the columns of 'input'.} \item{timestep}{a non-negative integer specifying the number of timesteps between the existing timepoints (defaults to \code{1}, if not specified).} \item{motionline}{a integer vector giving the timepoints of the resulting matrix (derived from timepoints and timesteps by default).} } \description{ Interpolate rows of a matrix to yield a smooth transitions. } \examples{ len = 10 x = sin(seq(0,2*pi,length=len*2)) fun = function(){n=sample(1:len,1);return(x[n:(n+len-1)])} input = t(replicate(7,fun(),simplify=TRUE)) input = input + rnorm(length(input))/2 par(mfrow=c(1,2)) plotmatrix(input,main="original",cols=1:7,type="o") mov = makemovie(input,timestep=0.2) plotmatrix(mov,main="interpolated",cols=1:7,type="o") } \seealso{ \code{\link{clusterplot}}, \code{\link{align}}, \code{\link{demotour}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{matrix} LSD/man/singlefusionplot.Rd0000755000176200001440000000511613672347441015363 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.fusionplot.R \name{singlefusionplot} \alias{singlefusionplot} \alias{LSD.singlefusionplot} \title{Visualize two-dimensional data clusters (add to an existing plot)} \usage{ singlefusionplot( x, y, fromto = c(0.05, 0.95), colpal = "standardheat", simulate = FALSE, daltonize = FALSE, cvd = "p", nrcol = 25, outer.col = "grey", rev = FALSE, alpha = NULL, quartiles.col = c("grey", "black", "grey"), add.quartiles = TRUE ) } \arguments{ \item{x}{a numeric vector.} \item{y}{a numeric vector.} \item{fromto}{a numeric vector containing the range of quantiles (between 0 and 1) to be plotted.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified).} \item{outer.col}{R built-in color to be used for outlier lines (lines outside of 'fromto').} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{quartiles.col}{a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')).} \item{add.quartiles}{logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles.} } \description{ Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion (add to an existing plot). } \examples{ x = 1:1000/300 y = rnorm(1000)+sin(2*x)*3 emptyplot(xlim = range(x),ylim = range(y)) singlefusionplot(x,y,colpal = "ylgnbu") axis(1) axis(2) box() } \seealso{ \code{\link{fusionplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{cluster} LSD/man/linesplot.Rd0000755000176200001440000000412713672347441013771 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.linesplot.r \name{linesplot} \alias{linesplot} \alias{LSD.linesplot} \title{One-dimensional scatterplot} \usage{ linesplot( x, labels = NULL, col = "black", cols = NULL, alpha = 25, xlim = NULL, ylim = NULL, xlab = NULL, ylab = "", las = 1, outline = TRUE, cexbox = 0.6, addboxes = FALSE, border = "black", range = 1.5, lwd = 1.5, main = "LSD.linesplot", ... ) } \arguments{ \item{x}{numeric data as vector, matrix, list or data.frame.} \item{labels}{a character vector of labels.} \item{col}{a R build-in color.} \item{cols}{a character vector of R build-in colors.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{xlab}{x label, standard graphics parameter.} \item{ylab}{y label, standard graphics parameter.} \item{las}{las=1: horizontal text, las=2: vertical text (x-axis labels).} \item{outline}{logical: if \code{TRUE} (by default), outliers are plotted.} \item{cexbox}{a numerical value giving the amount by which the boxes should be magnified relative to the default.} \item{addboxes}{logical: if \code{TRUE} (\code{FALSE} by default), boxplots be added to the plot.} \item{border}{a R build-in color for the box and the whiskers (if \code{addboxes = TRUE}).} \item{range}{this determines how far the plot whiskers extend out from the box.} \item{lwd}{linewidth of the box and whiskers.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{...}{additional parameters to be passed to points and plot.} } \description{ Visualize one-dimensional data in its every detail. } \examples{ l = list() for (i in 1:10){l[[i]] = rnorm(100,sqrt(i^2.5),1+i/2)} linesplot(l,alpha=25,border="darkred",addboxes = TRUE,outline=FALSE) } \seealso{ \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{boxplotlike} LSD/man/heatscatter.Rd0000755000176200001440000001056213672347441014267 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.heatscatter.R \name{heatscatter} \alias{heatscatter} \alias{LSD.heatscatter} \title{A colored scatterplot based on a two-dimensional Kernel Density Estimation} \usage{ heatscatter( x, y, pch = 19, cexplot = 0.5, nrcol = 30, grid = 100, colpal = "heat", simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, rev = FALSE, xlim = NULL, ylim = NULL, xlab = NULL, ylab = NULL, main = "heatscatter", cor = FALSE, method = "spearman", only = "none", add.contour = FALSE, nlevels = 10, color.contour = "black", greyscale = FALSE, log = "", ... ) } \arguments{ \item{x}{a numeric vector.} \item{y}{a numeric vector.} \item{pch}{plotting 'character'. This can either be a single character or an integer code for one of a set of graphics symbols. (see '?pch', to be passed to plot).} \item{cexplot}{a numerical value giving the amount by which the points should be magnified relative to the default.} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} \item{grid}{an integer specifying the size of the grid used for the KDE.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{xlab}{x labels, standard graphics parameter.} \item{ylab}{y labels, standard graphics parameter.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{cor}{logical: if \code{TRUE} (\code{FALSE} by default), the correlation is added to the title.} \item{method}{a character specifying the correlation method to use ('spearman' (default), 'pearson' or 'kendall').} \item{only}{a character string which contains 'x' if the density should only be computed for the x axis, 'y' for the y axis (defaults to 'none' for the two-dimensional case).} \item{add.contour}{logical: if \code{TRUE} (\code{FALSE} by default), the contour lines are added to the plot.} \item{nlevels}{an integer giving the number of levels of the contour lines.} \item{color.contour}{R build-in color for the contour lines.} \item{greyscale}{logical: if \code{TRUE} (\code{FALSE} by default), the used colorpalette is converted to greyscales.} \item{log}{a character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic.} \item{...}{additional parameters to be passed to points and plot.} } \description{ Visualize two dimensional data in a three dimensional fashion facilitating a color encoded Kernel Density Estimation. } \note{ Two-Dimensional Kernel Density Estimation adapted and modified from Venables and Ripley's MASS package (see reference). } \examples{ points = 10^4 x = c(rnorm(points/2),rnorm(points/2)+4) y = x + rnorm(points,sd=0.8) x = sign(x)*abs(x)^1.3 heatscatter(x,y) heatscatter(x,y,colpal="bl2gr2rd",main="bl2gr2rd",cor=FALSE) heatscatter(x,y,cor=FALSE,add.contour=TRUE,color.contour="red",greyscale=TRUE) heatscatter(x,y,colpal="spectral",cor=FALSE,add.contour=TRUE) } \references{ Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{heatcolors} \keyword{scatterplot} LSD/man/heathist.Rd0000755000176200001440000000555513672347441013577 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.heathist.r \name{heathist} \alias{heathist} \alias{LSD.heathist} \title{Color a histogram} \usage{ heathist( x, breaks = 20, xlab = NULL, ylab = NULL, main = "heathist", colpal = "greys", rev = FALSE, simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, nobox = FALSE, add.density = FALSE, col.density = "darkred", add.rug = TRUE, col.rug = "black", nrcol = 100, ... ) } \arguments{ \item{x}{a numeric vector.} \item{breaks}{a numeric value giving the breaks of the histogram.} \item{xlab}{x label, standard graphics parameter.} \item{ylab}{y label, standard graphics parameter.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{nobox}{logical: if \code{TRUE} (\code{FALSE} by default), the box of the plot is omitted.} \item{add.density}{if \code{TRUE} (\code{FALSE} by default), a density line is added to the histogram.} \item{col.density}{a R build-in color for the density line (if \code{add.density = TRUE}).} \item{add.rug}{if \code{TRUE} (\code{FALSE} by default), a rug (1-d plot of the data) is added below the histogram-bars.} \item{col.rug}{a R build-in color for the rug (if \code{add.rug = TRUE}).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} \item{...}{additional parameters to be passed to points and plot.} } \description{ A histogram with an additional color stripe based on a kernel density estimate. } \examples{ x = rnorm(1000,mean = sample(c(0,3),size = 1000,prob = c(0.4,0.6),replace = TRUE)) heathist(x,xlab="x",add.density=TRUE,col.rug="darkred") heathist(x,xlab="x",colpal = "matlablike") } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{histogram} LSD/man/colorpalette.Rd0000755000176200001440000000373513672347441014461 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{colorpalette} \alias{colorpalette} \alias{LSD.colorpalette} \title{Provides colorpalettes containing R built-in colors} \usage{ colorpalette( colpal, nrcol = NULL, simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, rev = FALSE ) } \arguments{ \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to length of \code{colpal}, if not specified).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is returned to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is returned to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is returned.} } \value{ \code{colorpalette} returns a vector containing R built-in colors in hexadecimal representation. } \description{ Provides pre-designed colorpalettes (character vectors containing R built-in colors) of this and several other R packages (grDevices, RColorBrewer, colorRamps) as well as custom-made ones. } \examples{ colorpalette("heat") colorpalette(c("darkred","grey","darkblue"),10) } \seealso{ \code{\link{disco}}, \code{\link{demotour}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{alpha} \keyword{color} LSD/man/daltonize.Rd0000755000176200001440000000237413672347441013753 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{daltonize} \alias{daltonize} \alias{LSD.daltonize} \title{Dichromat vision simulation for colorpalettes} \usage{ daltonize(colpal, cvd = "p", show = TRUE) } \arguments{ \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{show}{logical: if \code{TRUE} (by default), the resulting colorpalettes are depicted in an R plot.} } \value{ \code{daltonize} returns a list, where each entry is a vector containing R built-in colors in hexadecimal representation: \item{simulated}{vector of simulated colors} \item{enhanced}{vector of enhanced colors} } \description{ Dichromat vision simulation and enhancement according to \url{http://www.daltonize.org}. } \examples{ daltonize("heat",cvd = "d") daltonize("colorblind",cvd = "p") } \references{ \url{http://www.daltonize.org} } \seealso{ \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{colorblind} \keyword{daltonize} LSD/man/complementarycolor.Rd0000755000176200001440000000152413672347441015674 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{complementarycolor} \alias{complementarycolor} \alias{LSD.complementarycolor} \title{Complement R colors} \usage{ complementarycolor(cols, alpha = NULL) } \arguments{ \item{cols}{a character vector containing R built-in colors.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} } \value{ \code{complementarycolor} returns a vector containing R built-in colors in hexadecimal representation. } \description{ Convert R built-in colors to their color complement } \examples{ complementarycolor(c("red","green","blue")) } \seealso{ \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{color} LSD/man/emptyplot.Rd0000755000176200001440000000124013672347441014006 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.utilities.R \name{emptyplot} \alias{emptyplot} \alias{LSD.emptyplot} \title{Wrapper function for an empty graphics device} \usage{ emptyplot(xlim = c(-1, 1), ylim = c(-1, 1), ...) } \arguments{ \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{...}{additional parameters to be passed to points and plot.} } \description{ Calls an empty graphics device with a coordinate system of choice. } \examples{ emptyplot() } \seealso{ \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{empty} \keyword{plotting} \keyword{region} LSD/man/heatbarplot.Rd0000755000176200001440000000412313672347441014261 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.comparisonplot.r \name{heatbarplot} \alias{heatbarplot} \alias{LSD.heatbarplot} \title{Color a barplot.} \usage{ heatbarplot( x, colpal = "heat", simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, rev = FALSE, horizontal = FALSE, nrcol = 100, ... ) } \arguments{ \item{x}{a histogram object.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{horizontal}{logical: if \code{TRUE} (\code{FALSE} by default), rotation of 90 degrees is applied.} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} \item{...}{additional parameters to be passed to points and plot.} } \description{ Depict a histogram object as a barplot in a color encoded fashion based on a kernel density estimate. } \examples{ points = 10^4 x = c(rnorm(points/2),rnorm(points/2)+4) x = sign(x)*abs(x)^1.3 xhist = hist(x,plot = FALSE) heatbarplot(xhist) } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{barplot} LSD/man/heatboxplot.Rd0000755000176200001440000001076513672347441014316 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.heatboxplot.R \name{heatboxplot} \alias{heatboxplot} \alias{LSD.heatboxplot} \title{Heatboxplot: a colored boxplot} \usage{ heatboxplot( x, horizontal = FALSE, add = FALSE, colpal = "standard", rev = FALSE, simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, colpals = NULL, nrcol = 75, lwd = 1.75, axes = TRUE, labels = NULL, xlim = NULL, ylim = NULL, xlab = NULL, ylab = "", main = "heatboxplot", nolab = FALSE, outline = TRUE, boxonly = FALSE, adjust = 1, quant.from = 0.25, quant.to = 0.75, range = 1.5, border = "black", plot.boxplot = TRUE, add.quartiles = TRUE, add.box = FALSE, n.density = 1024, cexbox = 0.6, ... ) } \arguments{ \item{x}{data as vector, matrix, list or data.frame.} \item{horizontal}{logical: if \code{TRUE} (\code{FALSE} by default), rotation of 90 degrees is applied.} \item{add}{logical: if \code{TRUE} (\code{FALSE} by default), the boxplot is added to an existing plot.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{colpals}{a character vector containing names of \code{LSD} colorpalettes (see disco() or \code{\link{disco}}).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} \item{lwd}{linewidth of the box and whiskers.} \item{axes}{logical: if \code{TRUE} (by default), the axes are plotted.} \item{labels}{a character vector of labels.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{xlab}{x label, standard graphics parameter.} \item{ylab}{y label, standard graphics parameter.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{nolab}{logical: if \code{TRUE} (\code{FALSE} by default), the title and ylab are suppressed.} \item{outline}{logical: if \code{TRUE} (by default), outliers are plotted.} \item{boxonly}{logical: if \code{TRUE} (\code{FALSE} by default), the density is only be plotted in the box.} \item{adjust}{a numeric value giving the scaling factor for the used bandwidth (defaults to 1).} \item{quant.from}{a numeric value (between 0 and 1) giving the quantile from which the density lane should be plotted.} \item{quant.to}{a numeric value (between 0 and 1) giving the quantile to which the density lane should be plotted.} \item{range}{a numeric value to determine how far the plot whiskers extend out from the box.} \item{border}{an R build-in color for the box and whiskers.} \item{plot.boxplot}{logical: if \code{TRUE} (by default), the boxplot is added to the density.} \item{add.quartiles}{if \code{TRUE} (\code{FALSE} by default), only the box of the boxplot is added (if \code{plot.boxplot = FALSE}).} \item{add.box}{logical: if \code{TRUE} (by default), the box is added to the plot.} \item{n.density}{an integer specifying the number of equally spaced points at which the density is to be estimated.} \item{cexbox}{a numerical value giving the amount by which the boxes should be magnified relative to the default.} \item{...}{additional parameters to be passed to points and plot.} } \description{ A boxplot with an additional color stripe based on a kernel density estimate. } \examples{ f = c(rnorm(200),rnorm(200)+4) h = rf(500,15,15)*10 g = rnorm(300)+1 heatboxplot(h) heatboxplot(list(f=f,g=g),colpals=c("rdpu","greens"),labels=c("bimodal","unimodal")) } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{boxplot} LSD/man/windowxy.Rd0000755000176200001440000000110713672347441013643 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.utilities.R \name{windowxy} \alias{windowxy} \alias{LSD.windowxy} \title{Factorization of the number of windows for plots with device partitions} \usage{ windowxy(nrwin = 1) } \arguments{ \item{nrwin}{a non-negative integer specifying the number of windows.} } \description{ Create a factorization of the number of windows for plots with device partitions to be used in par(mfrow = ...). } \examples{ windowxy(20) } \seealso{ \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{factorization} LSD/man/distinctcolors.Rd0000755000176200001440000000301013672347441015011 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{distinctcolors} \alias{distinctcolors} \alias{LSD.distinctcolors} \title{Find preferably distinct R built-in colors} \usage{ distinctcolors( nrcol = 10, method = "RGB", bw = FALSE, show = TRUE, simulate = TRUE ) } \arguments{ \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to the length of \code{10}, if not specified).} \item{method}{character string implying the method for color selection to be used ("RGB" uses a grid in the RGB space (default), "Lab" uses a grid in the Lab space, "goldenratio" uses the golden ratio as spacing between colors in the HSV color space).} \item{bw}{logical: if \code{TRUE} (\code{FALSE} by default), the colors "black" and "white" are removed from the resulting colorpalette.} \item{show}{logical: if \code{TRUE} (by default), the resulting colorpalettes are depicted in an R plot.} \item{simulate}{logical: if \code{TRUE} (by default), a converted colorpalettes are additionally depicted to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} } \value{ \code{distinctcolors} returns a vector containing R built-in colors in hexadecimal representation. } \description{ Find a vector of distinct R built-in colors for a pre-defined length ('nrcol'). } \examples{ distinctcolors() } \seealso{ \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{color} LSD/man/clusterplot.Rd0000755000176200001440000001044513672347441014340 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.clusterplot.R \name{clusterplot} \alias{clusterplot} \alias{LSD.clusterplot} \title{Visualize two-dimensional data clusters} \usage{ clusterplot( input, label = NULL, at = NULL, main = NULL, xlim = NULL, ylim = NULL, xlabels = NULL, fromto = c(0.05, 0.95), colpal = "standardheat", simulate = FALSE, daltonize = FALSE, cvd = "p", nrcol = 25, outer.col = "lightgrey", quartiles.col = c("grey", "black", "grey"), add.quartiles = TRUE, separate = TRUE, rev = FALSE, size = TRUE, alpha = NULL, axes = TRUE, ... ) } \arguments{ \item{input}{matrix or list with numerical entries.} \item{label}{a character vector assigning rows/elements of 'input' to clusters (if specified, multiple clusters can be depicted in different colors and/or subsequent plots).} \item{at}{a integer vector containing the x-positions corresponding to the columns of 'input'.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{xlabels}{a character vector containing labels for the x-axis.} \item{fromto}{a numeric vector containing the range of quantiles (between 0 and 1) to be plotted.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified).} \item{outer.col}{R built-in color to be used for outlier lines (lines outside of 'fromto').} \item{quartiles.col}{a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')).} \item{add.quartiles}{logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles.} \item{separate}{if \code{TRUE} (by default), different clusters are depicted in subsequent plots.} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{size}{logical: if \code{TRUE} (by default), the size of each cluster is added to the title of the respective plot.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{axes}{logical: if \code{TRUE} (by default), a box and axes are added to the plot (if \code{FALSE}, custom specification of axes can be achieved via basic R graphics functions).} \item{...}{additional parameters to be passed to points and plot.} } \description{ Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion. } \examples{ samples = 100 probes = 75 at = 1:probes clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) clus = rbind( t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples, t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) quartiles.col = c("transparent","black","transparent") colpal = c("standardheat","crazyblue","crazyred","crazygreen") labs = paste("cluster",kmeans(clus,4)$cluster) clusterplot(clus,fromto=c(0,1)) clusterplot(clus,labs,separate=FALSE,xaxt="n",fromto=c(0.4,0.6),colpal=colpal, outer.col="none",ylim=c(-2,3),quartiles.col = quartiles.col) clusterplot(clus,labs,colpal=colpal) labs = paste("cluster",kmeans(clus,2)$cluster) colpal = c("greens","purples") clusterplot(clus,labs,separate=FALSE,xaxt="n",fromto=c(0.3,0.7),colpal=colpal, outer.col="none",ylim=c(-1,2),alpha=50,quartiles.col = quartiles.col) } \seealso{ \code{\link{singleclusterplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{cluster} LSD/man/align.Rd0000755000176200001440000000516513672347441013055 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.align.R \name{align} \alias{align} \alias{LSD.align} \title{Visualize two-dimensional data in a color encoded fashion} \usage{ align( input, colpal = "heat", simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, label = FALSE, digits = 1, border = NULL, xlim = NULL, ylim = NULL, main = NULL, axes = TRUE, ... ) } \arguments{ \item{input}{matrix or list with any type of entries.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{label}{logical: if \code{TRUE} (\code{FALSE} by default), labels are added according to the color scheme (i.e. binning).} \item{digits}{integer indicating the number of decimals to be used for binning of continuous data.} \item{border}{color for rectangle border(s). Use border = NA to omit borders.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{main}{title of the plot, standard graphics parameter.} \item{axes}{logical: if \code{TRUE} (by default), a box and axes are added to the plot (if \code{FALSE}, custom specification of axes can be achieved via basic R graphics functions).} \item{...}{additional parameters to be passed to points and plot.} } \description{ Depict any matrix or list in a color encoded rectangular fashion. } \examples{ data(seqs) colpal = c("A" = "darkgreen","C" = "darkblue","G" = "yellow","T" = "darkred") align(seqs,colpal = colpal,label = TRUE,main = "DNA sequences") data(homer) colpal = c("white","black","yellow","wheat3") align(homer,colpal = colpal,main = "D'OH!",asp = 1,axes = FALSE) } \seealso{ \code{\link{clusterplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Phillipp Torkler, Bjoern Schwalb } \keyword{alignment} \keyword{sequence} LSD/man/singleclusterplot.Rd0000755000176200001440000000553513672347441015546 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.clusterplot.R \name{singleclusterplot} \alias{singleclusterplot} \alias{LSD.singleclusterplot} \title{Visualize two-dimensional data clusters (add to an existing plot)} \usage{ singleclusterplot( input, at = NULL, fromto = c(0.05, 0.95), colpal = "standardheat", simulate = FALSE, daltonize = FALSE, cvd = "p", nrcol = 25, outer.col = "lightgrey", rev = FALSE, alpha = NULL, quartiles.col = c("grey", "black", "grey"), add.quartiles = TRUE ) } \arguments{ \item{input}{matrix or list with numerical entries.} \item{at}{a integer vector containing the x-positions corresponding to the columns of 'input'.} \item{fromto}{a numeric vector containing the range of quantiles (between 0 and 1) to be plotted.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified).} \item{outer.col}{R built-in color to be used for outlier lines (lines outside of 'fromto').} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{quartiles.col}{a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')).} \item{add.quartiles}{logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles.} } \description{ Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion (add to an existing plot). } \examples{ samples = 100 probes = 200 clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) clus = rbind( t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples, t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) emptyplot(xlim = c(1,ncol(clus)),ylim = range(clus)) singleclusterplot(clus) axis(1) axis(2) box() } \seealso{ \code{\link{clusterplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{cluster} LSD/man/singlemsdplot.Rd0000755000176200001440000000277213672347441014650 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.msdplot.r \name{singlemsdplot} \alias{singlemsdplot} \alias{LSD.singlemsdplot} \title{Visualize two-dimensional data clusters (add to an existing plot)} \usage{ singlemsdplot( input, col = "darkgreen", alpha = 50, bars = TRUE, length = 0.25, at = NULL ) } \arguments{ \item{input}{data as matrix or list.} \item{col}{a character vector of R build-in colors.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{bars}{logical: if \code{TRUE} (by default), error bars are added at each position.} \item{length}{a numeric value scaling the width of the bars.} \item{at}{a integer vector containing the x-positions corresponding to the columns of 'input'.} } \description{ Depict a numeric matrix or list utilizing the underlying mean and standard deviation estimates of one dimension in a color encoded fashion (add to an existing plot). } \examples{ samples = 100 probes = 200 clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) clus = rbind( t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples, t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) emptyplot(xlim = c(1,ncol(clus)),ylim = range(clus)) singlemsdplot(clus) axis(1) axis(2) box() } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{mean} \keyword{sd} LSD/man/plotmatrix.Rd0000755000176200001440000000341013672347441014155 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.plotmatrix.r \name{plotmatrix} \alias{plotmatrix} \alias{LSD.plotmatrix} \title{Visualize two-dimensional data} \usage{ plotmatrix( input, xlim = NULL, ylim = NULL, xlab = "", ylab = "", main = "plotmatrix", type = "l", lwd = 2, at = NULL, xlabels = NULL, ltys = NULL, add = FALSE, cols = NULL, ... ) } \arguments{ \item{input}{a matrix with numerical entries.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{xlab}{x lab, standard graphics parameter.} \item{ylab}{y lab, standard graphics parameter.} \item{main}{title of the plot, standard graphics parameter.} \item{type}{what 'type' of plot should be drawn (to be passed to points).} \item{lwd}{a positive number giving the line width.} \item{at}{a integer vector containing the x-positions corresponding to the columns of 'input'.} \item{xlabels}{a character vector containing labels for the x-axis.} \item{ltys}{a numeric vector giving the line types for each row of 'input'.} \item{add}{logical: if \code{TRUE} (\code{FALSE} by default), lines are added to existing plot.} \item{cols}{a character vector of R build-in colors.} \item{...}{additional parameters to be passed to points and plot.} } \description{ Plot the rows of a matrix as lines along the cols. } \examples{ len = 20 x = sin(seq(0,2*pi,length=len*2)) fun = function(){n=sample(1:len,1); return(x[n:(n+len-1)])} input = t(replicate(7,fun(),simplify=TRUE)) input = input + rnorm(length(input))/2 plotmatrix(input,cols=1:7) } \seealso{ \code{\link{clusterplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{matrix} LSD/man/homer.Rd0000755000176200001440000000032512452063406013055 0ustar liggesusers\name{homer} \docType{data} \alias{homer} \title{homer} \description{Homer Simpson as a list!} \usage{homer} \format{This list contains 31 character vectors of length 22 encoding Homer Simpson.} \keyword{dataset} LSD/man/disco.Rd0000755000176200001440000000203313672347441013053 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{disco} \alias{disco} \alias{LSD.disco} \alias{display.colorpalette} \alias{LSD.display.colorpalette} \title{Disco (DISplays COlorpalettes)} \usage{ disco(colpal = NULL, nrcol = NULL, alpha = NULL) } \arguments{ \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (displays all colorpalettes, if not specified).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to length of \code{colpal}, if not specified).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} } \description{ Displays pre-designed colorpalettes as well as custom-made ones (see \code{colorpalette}). } \examples{ disco() disco("rdbu",10) } \seealso{ \code{\link{colorpalette}}, \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{alpha} \keyword{color} LSD/man/seqs.Rd0000755000176200001440000000034712452063442012722 0ustar liggesusers\name{seqs} \docType{data} \alias{seqs} \title{seqs} \description{TATAbox containing DNA-sequences!} \usage{seqs} \format{This list contains 20 character vectors of TATAbox containing DNA-sequences of length 30.} \keyword{dataset} LSD/man/densitylane.Rd0000755000176200001440000000413113672347441014272 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.heatboxplot.R \name{densitylane} \alias{densitylane} \alias{LSD.densitylane} \title{Visualize a density in a rectangular fashion} \usage{ densitylane( x, y, pos = 1, width = 0.4, colpal = "standard", rev = FALSE, simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, horizontal = horizontal, nrcol = 75 ) } \arguments{ \item{x}{density$x values of a density object.} \item{y}{density$y values of a density object.} \item{pos}{the x co-ordinate of the lane (mid point).} \item{width}{a numeric value giving the width of the lane.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{horizontal}{logical: if \code{TRUE} (\code{FALSE} by default), rotation of 90 degrees is applied.} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} } \description{ Add a color stripe to an existing plot based on a kernel density estimate. } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{density} LSD/man/comparisonplot.Rd0000755000176200001440000000566513672347441015041 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.comparisonplot.r \name{comparisonplot} \alias{comparisonplot} \alias{cplot} \title{Comparisonplot: a fancy scatterplot} \usage{ comparisonplot( x, y, histbreaks = 30, adjust = 1, colpal = "heat", simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, rev = FALSE, main = "comparisonplot", cor = FALSE, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, ab = FALSE, add.density = FALSE, col.density = "darkred", pimp = FALSE, ... ) } \arguments{ \item{x}{a numeric vector.} \item{y}{a numeric vector.} \item{histbreaks}{a non-negative integer specifying the number of breaks of the histograms.} \item{adjust}{scale the used bandwidth of the density estimate, if \code{add.density = TRUE}.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{cor}{if \code{TRUE} (\code{FALSE} by default), the correlation is added to the title.} \item{xlab}{x label, standard graphics parameter.} \item{ylab}{y label, standard graphics parameter.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{ab}{if \code{TRUE} (\code{FALSE} by default), \code{abline(0,1)} is added to the heatscatter.} \item{add.density}{if \code{TRUE} (\code{FALSE} by default), density lines are added to the barplots.} \item{col.density}{R built-in color to specify the color of the density line.} \item{pimp}{if \code{TRUE} (\code{FALSE} by default), the plot is pimped.} \item{...}{additional parameters to be passed to points and plot.} } \description{ A function to compare two vectors extensively. } \examples{ points = 10^4 x = c(rnorm(points/2),rnorm(points/2)+4) y = x + rnorm(points,sd=0.8) x = sign(x)*abs(x)^1.3 comparisonplot(x,y,histbreaks=30,pch=20) } \seealso{ \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{barplot} \keyword{scatterplot} LSD/man/fusionplot.Rd0000755000176200001440000000711313672347441014160 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.fusionplot.R \name{fusionplot} \alias{fusionplot} \alias{LSD.fusionplot} \title{Visualize two-dimensional data clusters} \usage{ fusionplot( x, y, label = NULL, main = NULL, xlim = NULL, ylim = NULL, fromto = c(0.05, 0.95), colpal = "standardheat", simulate = FALSE, daltonize = FALSE, cvd = "p", nrcol = 25, outer.col = "lightgrey", quartiles.col = c("grey", "black", "grey"), add.quartiles = TRUE, separate = TRUE, rev = FALSE, size = TRUE, alpha = NULL, axes = TRUE, ... ) } \arguments{ \item{x}{a numeric vector.} \item{y}{a numeric vector.} \item{label}{a character vector assigning rows/elements of 'input' to clusters (if specified, multiple clusters can be depicted in different colors and/or subsequent plots).} \item{main}{title(s) of the plot, standard graphics parameter.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{fromto}{a numeric vector containing the range of quantiles (between 0 and 1) to be plotted.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified).} \item{outer.col}{R built-in color to be used for outlier lines (lines outside of 'fromto').} \item{quartiles.col}{a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')).} \item{add.quartiles}{logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles.} \item{separate}{if \code{TRUE} (by default), different clusters are depicted in subsequent plots.} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{size}{logical: if \code{TRUE} (by default), the size of each cluster is added to the title of the respective plot.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{axes}{logical: if \code{TRUE} (by default), a box and axes are added to the plot (if \code{FALSE}, custom specification of axes can be achieved via basic R graphics functions).} \item{...}{additional parameters to be passed to points and plot.} } \description{ Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion. } \examples{ nr = 750 x = 1:nr/300 y = c(rnorm(nr)+sin(2*x)*3,rnorm(nr)+sin(2*x+pi/2)*3) x = c(x,x) labs = paste("cluster",c(rep(c(1,2),each = nr))) colpals = c("oranges","pubu") qcol = c("transparent","black","transparent") fusionplot(x,y,labs,separate=FALSE,colpal=colpals,alpha=75,quartiles.col = qcol) } \seealso{ \code{\link{singlefusionplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Achim Tresch, Bjoern Schwalb } \keyword{cluster} LSD/man/ellipsescatter.Rd0000755000176200001440000000405313672347441015001 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.ellipsescatter.R \name{ellipsescatter} \alias{ellipsescatter} \alias{LSD.ellipsescatter} \title{Visualize subgroups of two-dimensional data assuming normal distributions} \usage{ ellipsescatter( x, y, groups, colors = NULL, pch = 20, bgcol = "darkgrey", main = "ellipsescatter", xlab = NULL, ylab = NULL, scalesd = 1, level = 0.75, legend.cex = 1, location = "topright", ... ) } \arguments{ \item{x}{a numeric vector.} \item{y}{a numeric vector.} \item{groups}{a list of indices or vector names to be plotted as groups (not necessarily all of x and y).} \item{colors}{a character vector of R build-in colors corresponding to the chosen groups.} \item{pch}{the plotting character (to be passed to plot).} \item{bgcol}{a R build-in color for non-grouped points.} \item{main}{title(s) of the plot, standard graphics parameter.} \item{xlab}{x label, standard graphics parameter.} \item{ylab}{y label, standard graphics parameter.} \item{scalesd}{a numeric value giving the scaling factor for standard deviations in each dimension (defaults to 1).} \item{level}{a numeric value (between 0 and 1) giving the confidence level of a pairwise confidence region.} \item{legend.cex}{a numerical value giving the amount by which the added legend should be magnified relative to the default.} \item{location}{the x and y co-ordinates to be used to position the legend (see 'xy.coords').} \item{...}{additional parameters to be passed to points and plot.} } \description{ A scatterplot with additional colored ellipses based on a gaussianity assumption. } \examples{ x = c(rnorm(50),rnorm(100,2),rnorm(50,4)) y = (x + rnorm(200,0,0.8))*rep(c(1,4,1),c(50,100,50)) x = sign(x)*abs(x)^1.3 groups = list("Green" = 1:50,"Red" = 51:150,"Blue" = 151:200) colors = c("darkgreen","darkred","darkblue") ellipsescatter(x,y,groups,colors,location = "topleft") } \seealso{ \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{scatterplot} LSD/man/heatscatterpoints.Rd0000755000176200001440000000761113672347441015525 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.heatscatter.R \name{heatscatterpoints} \alias{heatscatterpoints} \alias{LSD.heatscatterpoints} \title{A colored scatterplot based on a two-dimensional Kernel Density Estimation (add to an existing plot)} \usage{ heatscatterpoints( x, y, pch = 19, cexplot = 0.5, nrcol = 30, grid = 100, colpal = "heat", simulate = FALSE, daltonize = FALSE, cvd = "p", alpha = NULL, rev = FALSE, xlim = NULL, ylim = NULL, only = "none", add.contour = FALSE, nlevels = 10, color.contour = "black", greyscale = FALSE, log = "", ... ) } \arguments{ \item{x}{a numeric vector.} \item{y}{a numeric vector.} \item{pch}{plotting 'character'. This can either be a single character or an integer code for one of a set of graphics symbols. (see '?pch', to be passed to plot).} \item{cexplot}{a numerical value giving the amount by which the points should be magnified relative to the default.} \item{nrcol}{a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified).} \item{grid}{an integer specifying the size of the grid used for the KDE.} \item{colpal}{a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified).} \item{simulate}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{daltonize}{logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}).} \item{cvd}{character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope).} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} \item{rev}{logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used.} \item{xlim}{x limits, standard graphics parameter.} \item{ylim}{y limits, standard graphics parameter.} \item{only}{a character string which contains 'x' if the density should only be computed for the x axis, 'y' for the y axis (defaults to 'none' for the two-dimensional case).} \item{add.contour}{logical: if \code{TRUE} (\code{FALSE} by default), the contour lines are added to the plot.} \item{nlevels}{an integer giving the number of levels of the contour lines.} \item{color.contour}{R build-in color for the contour lines.} \item{greyscale}{logical: if \code{TRUE} (\code{FALSE} by default), the used colorpalette is converted to greyscales.} \item{log}{a character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic.} \item{...}{additional parameters to be passed to points and plot.} } \description{ Visualize two dimensional data in a three dimensional fashion facilitating a color encoded Kernel Density Estimation (add to an existing plot). } \note{ Two-Dimensional Kernel Density Estimation adapted and modified from Venables and Ripley's MASS package (see reference). } \examples{ points = 10^4 x = c(rnorm(points/2),rnorm(points/2)+4) y = x + rnorm(points,sd=0.8) x = sign(x)*abs(x)^1.3 plot.new() plot.window(xlim = c(-5,15),ylim = c(-4,8)) heatscatterpoints(x,y,add.contour=TRUE,color.contour="green",greyscale=TRUE) axis(1) axis(2) box() } \references{ Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. } \seealso{ \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} } \author{ Bjoern Schwalb } \keyword{heatcolors} \keyword{scatterplot} LSD/man/convertcolor.Rd0000755000176200001440000000151413672347441014474 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{convertcolor} \alias{convertcolor} \alias{LSD.convertcolor} \title{Map R colors to hexadecimal representation} \usage{ convertcolor(cols, alpha = NULL) } \arguments{ \item{cols}{a character vector containing R built-in colors.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} } \value{ \code{convertcolor} returns a vector containing R built-in colors in hexadecimal representation. } \description{ Convert R built-in colors to hexadecimal representation. } \examples{ convertcolor(c("red","green","blue")) } \seealso{ \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{color} LSD/man/convertgrey.Rd0000755000176200001440000000146113672347441014325 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/LSD.color.r \name{convertgrey} \alias{convertgrey} \alias{LSD.convertgrey} \title{Convert R colors to greyscale} \usage{ convertgrey(cols, alpha = NULL) } \arguments{ \item{cols}{a character vector containing R built-in colors.} \item{alpha}{alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default).} } \value{ \code{convertgrey} returns a vector containing R built-in colors in hexadecimal representation. } \description{ Greyscale R built-in colors. } \examples{ convertgrey(c("red","green","blue")) } \seealso{ \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} } \author{ Bjoern Schwalb } \keyword{color} \keyword{greyscale} LSD/DESCRIPTION0000755000176200001440000000110413672363532012413 0ustar liggesusersPackage: LSD Version: 4.1-0 Date: 2020-06-16 Title: Lots of Superior Depictions Author: Bjoern Schwalb [aut, cre], Achim Tresch [aut], Phillipp Torkler [ctb], Sebastian Duemcke [ctb], Carina Demel [ctb], Brian Ripley [ctb], Bill Venables [ctb] Maintainer: Bjoern Schwalb Description: Create lots of colorful plots in a plethora of variations. Try the LSD demotour(). License: GPL-2 | GPL-3 LazyData: true RoxygenNote: 7.1.0 NeedsCompilation: no Packaged: 2020-06-17 09:20:26 UTC; bschwal Repository: CRAN Date/Publication: 2020-06-17 09:50:18 UTC LSD/R/0000755000176200001440000000000013672357763011120 5ustar liggesusersLSD/R/LSD.plotmatrix.r0000755000176200001440000000563412452755474014136 0ustar liggesusers ### plotmatrix ### #' @export #' @name plotmatrix #' @aliases LSD.plotmatrix #' @title Visualize two-dimensional data #' @description Plot the rows of a matrix as lines along the cols. #' @param input a matrix with numerical entries. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param xlab x lab, standard graphics parameter. #' @param ylab y lab, standard graphics parameter. #' @param main title of the plot, standard graphics parameter. #' @param type what 'type' of plot should be drawn (to be passed to points). #' @param lwd a positive number giving the line width. #' @param at a integer vector containing the x-positions corresponding to the columns of 'input'. #' @param xlabels a character vector containing labels for the x-axis. #' @param ltys a numeric vector giving the line types for each row of 'input'. #' @param add logical: if \code{TRUE} (\code{FALSE} by default), lines are added to existing plot. #' @param cols a character vector of R build-in colors. #' @param ... additional parameters to be passed to points and plot. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{clusterplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples len = 20 #' x = sin(seq(0,2*pi,length=len*2)) #' fun = function(){n=sample(1:len,1); return(x[n:(n+len-1)])} #' input = t(replicate(7,fun(),simplify=TRUE)) #' input = input + rnorm(length(input))/2 #' #' plotmatrix(input,cols=1:7) #' @keywords matrix plotmatrix = function(input,xlim = NULL,ylim = NULL,xlab = "",ylab = "",main = "plotmatrix",type = "l",lwd = 2,at = NULL,xlabels = NULL,ltys = NULL,add = FALSE,cols = NULL,...) { if (!is.matrix(input)) stop("First argument must be a matrix !") if (sum(is.na(input)) > 0) print("Be careful: Your data contains NAs ! NA containing rows will be omitted !") na.rows = apply(input,1,function(x){!(sum(is.na(x)) > 0)}) if (!all(na.rows)) stop("Your matrix contains not a single row without NAs !") input = input[na.rows,,drop = FALSE] if (is.null(at)){at=1:ncol(input)} if (is.null(xlabels)){xlabels = at} if (is.null(xlim)){xlim = c(1,max(at))} if (is.null(ylim)){ylim = range(input)} if (is.null(ltys)){ltys = rep(1,nrow(input))} if (is.null(cols)) {cols = rep("black", nrow(input))}else {if (length(cols) != nrow(input)) {if(length(cols) < nrow(input)){cols = rep(cols,ceiling(nrow(input)/length(cols)))} cols = cols[1:nrow(input)] cols[which(is.na(cols))] = "black" } } if(!add){ plot(c(at[1],median(input)),xlim=xlim,ylim=ylim,type="n",main="",xaxt="n",ylab=ylab,xlab=xlab,...) mtext(paste(main),3,2,cex=1.25) } axis(side=1,at=at,labels=xlabels,...) sapply(1:nrow(input),function(x){points(at,input[x,],col=cols[x],lty=ltys[x],type=type,lwd=lwd)}) points(c(at[1],median(input)),type = "n") } ### alias ### LSD.plotmatrix = plotmatrix LSD/R/LSD.color.r0000755000176200001440000010127513672347151013041 0ustar liggesusers ### daltonize ### #' @export #' @name daltonize #' @aliases LSD.daltonize #' @title Dichromat vision simulation for colorpalettes #' @description Dichromat vision simulation and enhancement according to \url{http://www.daltonize.org}. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param show logical: if \code{TRUE} (by default), the resulting colorpalettes are depicted in an R plot. #' @return \code{daltonize} returns a list, where each entry is a vector containing R built-in colors in hexadecimal representation: \item{simulated}{vector of simulated colors} \item{enhanced}{vector of enhanced colors} #' @author Bjoern Schwalb #' @seealso \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} #' @references \url{http://www.daltonize.org} #' @examples daltonize("heat",cvd = "d") #' daltonize("colorblind",cvd = "p") #' @keywords daltonize colorblind daltonize = function(colpal,cvd = "p",show = TRUE) { # Color Vision Deficiency Transformation Matrices # cvdtransform = switch(cvd, # protanope: reds are greatly reduced (1% men, 0,02% women) # p = matrix(data = c(0, 2.02344, -2.52581, 0, 1, 0, 0, 0, 1),nrow = 3,ncol = 3,byrow = TRUE), # deuteranope: greens are greatly reduced (1% men, 0,01% women) # d = matrix(data = c(1, 0, 0, 0.494207, 0, 1.24827, 0, 0, 1),nrow = 3,ncol = 3,byrow = TRUE), # tritanope: blues are greatly reduced (0,002% men, 0,001% women) # t = matrix(data = c(1, 0, 0, 0, 1, 0, -0.395913, 0.801109, 0),nrow = 3,ncol = 3,byrow = TRUE) ) # color management ### rgbvec = colorpalette(colpal) rgbmat = col2rgb(rgbvec) # conversion of RGB coordinates into LMS, a color space suitable for calculating color blindness as it's represented by the three types of cones of the human eye, named after their sensitivity at wavelengths; Long (564-580nm), Medium (534-545nm) and Short (420-440nm) # rgb2lms = matrix(data = c(17.8824, 43.5161, 4.11935, 3.45565, 27.1554, 3.86714, 0.0299566, 0.184309, 1.46709),nrow = 3,ncol = 3,byrow = TRUE) lmsmat = rgb2lms%*%rgbmat # simulation of color blindness by reducing the colors along a dichromatic confusion line, the line parallel to the axis of the missing photoreceptor, to a single color # simmat = cvdtransform%*%lmsmat # conversion of LMS coordinates into RGB # lms2rgb = solve(rgb2lms) simrgbmat = lms2rgb%*%simmat # adjust for numerical instability # simrgbmat = apply(simrgbmat,c(1,2),function(x){if (x>255){return(255)} else if (x<0){return(0)} else return(x)}) # conversion to hexadecimal color code # simpal = apply(round(simrgbmat),2,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) # compensation for color blindness by shifting wavelengths away from the portion of the spectrum invisible to the dichromat, towards the visible portion # # isolate invisible colors to color vision deficiency (calculate error matrix) # errormat = rgbmat - simrgbmat # shift colors towards visible spectrum (apply error modifications) # adjustmat = matrix(data = c(0, 0, 0, 0.7, 1, 0, 0.7, 0, 0),nrow = 3,ncol = 3,byrow = TRUE) compensationmat = adjustmat%*%errormat # add compensation to original values # enhancedrgbmat = compensationmat + rgbmat # adjust for numerical instability # enhancedrgbmat = apply(enhancedrgbmat,c(1,2),function(x){if (x>255){return(255)} else if (x<0){return(0)} else return(x)}) # conversion to hexadecimal color code # enhancedpal = apply(enhancedrgbmat,2,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) # simulation of color blindness for the compensation values # # conversion of RGB coordinates into LMS # testlmsmat = rgb2lms%*%enhancedrgbmat # simulation of color blindness # testsimmat = cvdtransform%*%testlmsmat # conversion of LMS coordinates into RGB # testsimrgbmat = lms2rgb%*%testsimmat # adjust for numerical instability # testsimrgbmat = apply(testsimrgbmat,c(1,2),function(x){if (x>255){return(255)} else if (x<0){return(0)} else return(x)}) # conversion to hexadecimal color code # testsimpal = apply(round(testsimrgbmat),2,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) # plot resulting colpals # if (show){ nr = length(rgbvec) # The nonlinear relations for L, a, and b are intended to mimic the nonlinear response of the eye. Furthermore, uniform changes of components in the Lab color space aim to correspond to uniform changes in perceived color, so the relative perceptual differences between any two colors in Lab can be approximated by treating each color as a point in a three dimensional space and taking the Euclidean distance between them # # linearize RGB # linsimmat = apply(simrgbmat/255,c(1,2),function(x){if (x <= 0.04045)return(x/12.92) else return(((x + 0.055)/(1 + 0.055))^(2.4))}) # conversion of RGB coordinates into XYZ (sRGB D65) ### rgb2xyz = matrix(data = c(0.4124564, 0.3575761, 0.1804375, 0.2126729, 0.7151522, 0.0721750, 0.0193339, 0.1191920, 0.9503041),nrow = 3,ncol = 3,byrow = TRUE) simxyzmat = rgb2xyz%*%linsimmat # tristimulus values of the reference white point: standard light source (D65) chosen according to 6500K color temperature (average daylight) # x = 0.312713 y = 0.329016 z = 1-x-y xn = x/y yn = 1 zn = z/y # conversion of XYZ coordinates into Lab ### sqfkt = function(x){if (x > (6/29)^3)return(x^(1/3)) else return((1/3)*(29/6)^2*x + (4/29))} simLabmat = apply(simxyzmat,2,function(x){L = 116*sqfkt(x[2]/yn) - 16;a = 500*(sqfkt(x[1]/xn) - sqfkt(x[2]/yn));b = 200*(sqfkt(x[2]/yn) - sqfkt(x[3]/zn));return(c(L,a,b))}) euclids = c() for (i in 1:nr){ diffmat = simLabmat - simLabmat[,i] euclids = c(euclids,apply(diffmat[,setdiff(1:nr,i),drop = FALSE],2,function(x){return(sqrt(sum(x^2)))})) } euclids = unique(euclids) # Euclidean perception difference score # Epds = min(euclids)/sqrt(100^2 + (2*128)^2 + (2*128)^2) npal = 4 plot(1,1,xlim=c(0,nr),ylim=c(0,npal*2),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") rect(xleft = 0:(nr - 1),ybottom = 1 - 1,xright = 1:nr,ytop = 1 - 0.2,col = testsimpal,border = NA) rect(xleft = 0,ybottom = 1 - 1,xright = nr,ytop = 1 - 0.2,col = "transparent",border = "darkgrey") rect(xleft = 0:(nr - 1),ybottom = 3 - 1,xright = 1:nr,ytop = 3 - 0.2,col = enhancedpal,border = NA) rect(xleft = 0,ybottom = 3 - 1,xright = nr,ytop = 3 - 0.2,col = "transparent",border = "darkgrey") rect(xleft = 0:(nr - 1),ybottom = 5 - 1,xright = 1:nr,ytop = 5 - 0.2,col = simpal,border = NA) rect(xleft = 0,ybottom = 5 - 1,xright = nr,ytop = 5 - 0.2,col = "transparent",border = "darkgrey") rect(xleft = 0:(nr - 1),ybottom = 7 - 1,xright = 1:nr,ytop = 7 - 0.2,col = rgbvec,border = NA) rect(xleft = 0,ybottom = 7 - 1,xright = nr,ytop = 7 - 0.2,col = "transparent",border = "darkgrey") cvdtype = switch(cvd,p = "protanope",d = "deuteranope",t = "tritanope") text(rep(nr/2,npal),c(8,6,4,2)-0.6,labels = c(paste("Original colors"),paste("Simulated colors as seen by",cvdtype,"individuals"),paste("Enhanced colors for",cvdtype,"individuals"),paste("Enhanced simulated colors as seen by",cvdtype,"individuals"))) mtext(paste("Euclidean perception difference score (Epds):",signif(Epds,1)),3,2,cex=1.25) mtext(paste("( should be >= 0.01 for sufficient perception differences )"),3,0,col="darkgrey") } # return colpals # return(list("simulated" = simpal,"enhanced" = enhancedpal)) } # alias # LSD.daltonize = daltonize ### colorpalette ### #' @export #' @name colorpalette #' @aliases LSD.colorpalette #' @title Provides colorpalettes containing R built-in colors #' @description Provides pre-designed colorpalettes (character vectors containing R built-in colors) of this and several other R packages (grDevices, RColorBrewer, colorRamps) as well as custom-made ones. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to length of \code{colpal}, if not specified). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is returned to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is returned to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is returned. #' @return \code{colorpalette} returns a vector containing R built-in colors in hexadecimal representation. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{disco}}, \code{\link{demotour}} #' @examples colorpalette("heat") #' colorpalette(c("darkred","grey","darkblue"),10) #' @keywords color alpha colorpalette = function(colpal,nrcol = NULL,simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,rev = FALSE) { if (length(colpal) > 1){palette = colpal} else{palette = switch(colpal, # custom-made palettes # heat = c("grey","darkblue","red","orange","gold"), crazyred = c( "#940000","#A50000","#FF5C5C","#FFB9B9"), crazygreen = c("dark green","#009700","green","#C0F5D0"), crazyblue = c("dark blue","blue","#7390EE","light blue"), mountain = c("light green","dark green","black","dark grey","#F0F0F0"), girly = c("violet","violetred","violetred1","purple","purple3"), jamaica = c("red","yellow","green"), standard = c("brown","gold","yellow","lightyellow","white"), colorblind = c("#000000","#E69F00","#56B4E9","#009E73","#F0E442","#0072B2","#D55E00","#CC79A7"), # palettes from the RColorBrewer package # ylorrd = rev(c("#FFFFCC","#FFEDA0","#FED976","#FEB24C","#FD8D3C","#FC4E2A","#E31A1C","#BD0026","#800026")), ylorbr = rev(c("#FFFFE5","#FFF7BC","#FEE391","#FEC44F","#FE9929","#EC7014","#CC4C02","#993404","#662506")), ylgnbu = rev(c("#FFFFD9","#EDF8B1","#C7E9B4","#7FCDBB","#41B6C4","#1D91C0","#225EA8","#253494","#081D58")), ylgn = rev(c("#FFFFE5","#F7FCB9","#D9F0A3","#ADDD8E","#78C679","#41AB5D","#238443","#006837","#004529")), reds = rev(c("#FFF5F0","#FEE0D2","#FCBBA1","#FC9272","#FB6A4A","#EF3B2C","#CB181D","#A50F15","#67000D")), rdpu = rev(c("#FFF7F3","#FDE0DD","#FCC5C0","#FA9FB5","#F768A1","#DD3497","#AE017E","#7A0177","#49006A")), purples = rev(c("#FCFBFD","#EFEDF5","#DADAEB","#BCBDDC","#9E9AC8","#807DBA","#6A51A3","#54278F","#3F007D")), purd = rev(c("#F7F4F9","#E7E1EF","#D4B9DA","#C994C7","#DF65B0","#E7298A","#CE1256","#980043","#67001F")), pubugn = rev(c("#FFF7FB","#ECE2F0","#D0D1E6","#A6BDDB","#67A9CF","#3690C0","#02818A","#016C59","#014636")), pubu = rev(c("#FFF7FB","#ECE7F2","#D0D1E6","#A6BDDB","#74A9CF","#3690C0","#0570B0","#045A8D","#023858")), orrd = rev(c("#FFF7EC","#FEE8C8","#FDD49E","#FDBB84","#FC8D59","#EF6548","#D7301F","#B30000","#7F0000")), oranges = rev(c("#FFF5EB","#FEE6CE","#FDD0A2","#FDAE6B","#FD8D3C","#F16913","#D94801","#A63603","#7F2704")), greys = rev(c("#FFFFFF","#F0F0F0","#D9D9D9","#BDBDBD","#969696","#737373","#525252","#252525","#000000")), greens = rev(c("#F7FCF5","#E5F5E0","#C7E9C0","#A1D99B","#74C476","#41AB5D","#238B45","#006D2C","#00441B")), gnbu = rev(c("#F7FCF0","#E0F3DB","#CCEBC5","#A8DDB5","#7BCCC4","#4EB3D3","#2B8CBE","#0868AC","#084081")), bupu = rev(c("#F7FCFD","#E0ECF4","#BFD3E6","#9EBCDA","#8C96C6","#8C6BB1","#88419D","#810F7C","#4D004B")), bugn = rev(c("#F7FCFD","#E5F5F9","#CCECE6","#99D8C9","#66C2A4","#41AE76","#238B45","#006D2C","#00441B")), blues = rev(c("#F7FBFF","#DEEBF7","#C6DBEF","#9ECAE1","#6BAED6","#4292C6","#2171B5","#08519C","#08306B")), spectral = c("#9E0142","#D53E4F","#F46D43","#FDAE61","#FEE08B","#FFFFBF","#E6F598","#ABDDA4","#66C2A5","#3288BD","#5E4FA2"), rdylgn = c("#A50026","#D73027","#F46D43","#FDAE61","#FEE08B","#FFFFBF","#D9EF8B","#A6D96A","#66BD63","#1A9850","#006837"), rdylbu = c("#A50026","#D73027","#F46D43","#FDAE61","#FEE090","#FFFFBF","#E0F3F8","#ABD9E9","#74ADD1","#4575B4","#313695"), rdgy = c("#67001F","#B2182B","#D6604D","#F4A582","#FDDBC7","#FFFFFF","#E0E0E0","#BABABA","#878787","#4D4D4D","#1A1A1A"), rdbu = c("#67001F","#B2182B","#D6604D","#F4A582","#FDDBC7","#F7F7F7","#D1E5F0","#92C5DE","#4393C3","#2166AC","#053061"), puor = c("#7F3B08","#B35806","#E08214","#FDB863","#FEE0B6","#F7F7F7","#D8DAEB","#B2ABD2","#8073AC","#542788","#2D004B"), prgn = c("#40004B","#762A83","#9970AB","#C2A5CF","#E7D4E8","#F7F7F7","#D9F0D3","#A6DBA0","#5AAE61","#1B7837","#00441B"), piyg = c("#8E0152","#C51B7D","#DE77AE","#F1B6DA","#FDE0EF","#F7F7F7","#E6F5D0","#B8E186","#7FBC41","#4D9221","#276419"), brbg = c("#543005","#8C510A","#BF812D","#DFC27D","#F6E8C3","#F5F5F5","#C7EAE5","#80CDC1","#35978F","#01665E","#003C30"), # palettes from the grDevices package # standardterrain = terrain.colors(9), standardtopo = topo.colors(9), standardheat = heat.colors(9), standardrainbow = rainbow(9,start=0.7,end=0.1), standardcm = cm.colors(9), # palettes from the colorRamps package # bl2gr = c("#0000FF","#001AE6","#0033CC","#004DB3","#006699","#008080","#009966","#00B34C","#00CC33","#00E619","#00FF00"), bl2gr2rd = c("#0000BF","#0000FF","#0080FF","#00FFFF","#40FFBF","#80FF80","#BFFF40","#FFFF00","#FF8000","#FF0000","#BF0000"), bl2rd = c("#0000FF","#0033FF","#0066FF","#0099FF","#00CCFF","#00FFFF","#FFCC00","#FF9900","#FF6600","#FF3300","#FF0000"), bl2yl = c("#0000FF","#1A1AE6","#3333CC","#4D4DB3","#666699","#808080","#999966","#B3B34C","#CCCC33","#E6E619","#FFFF00"), cy2yl = c("#00FFFF","#1AFFE6","#33FFCC","#4DFFB3","#66FF99","#80FF80","#99FF66","#B3FF4C","#CCFF33","#E6FF19","#FFFF00"), gr2rd = c("#00FF00","#1AE600","#33CC00","#4DB300","#669900","#808000","#996600","#B34C00","#CC3300","#E61900","#FF0000"), ma2gr = c("#FF00FF","#E61AE6","#CC33CC","#B34DB3","#996699","#808080","#669966","#4CB34C","#33CC33","#19E619","#00FF00"), matlablike = c("#0000AA","#0040FF","#0080FF","#40BFFF","#80FFFF","#BFFFBF","#FFFF80","#FFBF40","#FF8000","#FF4000","#AA0000"), matlablike2 = c("#0000BF","#0000FF","#0080FF","#00FFFF","#40FFBF","#80FF80","#BFFF40","#FFFF00","#FF8000","#FF0000","#BF0000") )} if (is.null(palette)){stop("'colpal' should be a valid colorpalette name (see 'disco()') or a character vector of at least two R built-in color names for interpolation!")} if (is.null(nrcol)){nrcol = length(palette)} palette = try(colorRampPalette(palette)(nrcol),silent = TRUE) if (class(palette) == "try-error"){stop("'colpal' should be a valid colorpalette name (see 'disco()') or a character vector of at least two R built-in color names for interpolation!")} if (rev){palette = rev(palette)} if (simulate){palette = daltonize(palette,cvd = cvd,show = FALSE)$simulated} if (daltonize){palette = daltonize(palette,cvd = cvd,show = FALSE)$enhanced} if (!is.null(alpha)){palette = convertcolor(palette,alpha)} return(palette) } # alias # LSD.colorpalette = colorpalette ### disco ### #' @export #' @name disco #' @aliases LSD.disco #' @aliases display.colorpalette #' @aliases LSD.display.colorpalette #' @title Disco (DISplays COlorpalettes) #' @description Displays pre-designed colorpalettes as well as custom-made ones (see \code{colorpalette}). #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (displays all colorpalettes, if not specified). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to length of \code{colpal}, if not specified). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @author Bjoern Schwalb #' @seealso \code{\link{colorpalette}}, \code{\link{demotour}} #' @examples disco() #' disco("rdbu",10) #' @keywords color alpha disco = function(colpal = NULL,nrcol = NULL,alpha = NULL) { if (is.null(colpal)){ if (is.null(nrcol)){nrcol = 11} # plot custom-made palettes # ownpals = c("colorblind","standard","crazyred","crazygreen","crazyblue","girly","jamaica","mountain","heat") pals = ownpals npal = length(ownpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the LSD package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) # plot palettes from the RColorBrewer package (part 1) # brewerpals = c("spectral","rdylgn","rdylbu","rdgy","rdbu","puor","prgn","piyg","brbg") pals = brewerpals npal = length(brewerpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the RColorBrewer package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) # plot palettes from the RColorBrewer package (part 2) # brewerpals = c("ylorrd","ylorbr","ylgnbu","ylgn","reds","rdpu","purples","purd","pubugn","pubu","orrd","oranges","greys","greens","gnbu","bupu","bugn","blues") pals = brewerpals npal = length(brewerpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the RColorBrewer package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) # plot palettes from the colorRamps package # rampspals = c("bl2gr","bl2gr2rd","bl2rd","bl2yl","cy2yl","gr2rd","ma2gr","matlablike","matlablike2") pals = rampspals npal = length(rampspals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the colorRamps package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) # plot palettes from the grDevices package # grpals = c("standardterrain","standardtopo","standardheat","standardrainbow","standardcm") pals = grpals npal = length(grpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the grDevices package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") } else { # plot user-specified colorpalette if 'colpal != NULL' # if (is.null(nrcol)){nrcol = length(colorpalette(colpal,nrcol,alpha = alpha))} plot(1,1,xlim=c(0,nrcol),ylim=c(0,8),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") rect(xleft = 0:(nrcol - 1),ybottom = 3,xright = 1:nrcol,ytop = 5,col = colorpalette(colpal,nrcol,alpha = alpha),border = NA) rect(xleft = 0,ybottom = 3,xright = nrcol,ytop = 5,col = "transparent",border = "darkgrey") if (length(colpal) > 1){mtext(paste("colorpalette"),3,2,cex=1.25)} else {mtext(paste(colpal,"colorpalette"),3,2,cex=1.25)} mtext(paste("( ",paste(colorpalette(colpal,nrcol,alpha = alpha),collapse = " ")," )"),3,0,col="darkgrey",cex=1 + ((1-0.25)*(nchar(paste("( ",paste(colorpalette(colpal,nrcol,alpha = alpha),collapse = " ")," )"))-50))/(50-185)) } } # aliases # LSD.disco = disco display.colorpalette = disco LSD.display.colorpalette = disco ### distinctcolors ### #' @export #' @name distinctcolors #' @aliases LSD.distinctcolors #' @title Find preferably distinct R built-in colors #' @description Find a vector of distinct R built-in colors for a pre-defined length ('nrcol'). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to the length of \code{10}, if not specified). #' @param method character string implying the method for color selection to be used ("RGB" uses a grid in the RGB space (default), "Lab" uses a grid in the Lab space, "goldenratio" uses the golden ratio as spacing between colors in the HSV color space). #' @param bw logical: if \code{TRUE} (\code{FALSE} by default), the colors "black" and "white" are removed from the resulting colorpalette. #' @param show logical: if \code{TRUE} (by default), the resulting colorpalettes are depicted in an R plot. #' @param simulate logical: if \code{TRUE} (by default), a converted colorpalettes are additionally depicted to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @return \code{distinctcolors} returns a vector containing R built-in colors in hexadecimal representation. #' @author Bjoern Schwalb #' @seealso \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} #' @examples distinctcolors() #' @keywords color distinctcolors = function(nrcol = 10,method = "RGB",bw = FALSE,show = TRUE,simulate = TRUE) { # get.permutations function # get.permutations = function(n,r,v = 1:n){ v = unique(sort(v)) v0 = vector(mode(v),0) sub = function(n,r,v){ if (r == 1){ matrix(v,n,1) } else if (n == 1) { matrix(v,1,r) } else { inner = Recall(n,r - 1,v) cbind(rep(v,rep(nrow(inner),n)),matrix(t(inner),ncol = ncol(inner),nrow = nrow(inner)*n,byrow = TRUE)) } } sub(n, r, v[1:n]) } if (method == "RGB"){ # 'RGB' uses a grid in the RGB space # # lay grid into the RGB space # lower = 1 while ((nrcol+2) > lower^3) lower = lower + 1 valseq = seq(0,255,length.out = lower) spl = get.permutations(length(valseq),3,valseq) # remove black and white # spl = spl[-c(1,nrow(spl)),] # sample nrcol of colors needed # spl = spl[sample(nrow(spl),nrcol),,drop=FALSE] # conversion to hexadecimal color code # colpal = apply(spl,1,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) # black and white? # if (!bw){colpal[1] = "#000000";colpal[length(colpal)] = "#FFFFFF"} } else if (method == "Lab"){ # 'Lab' uses a grid in the Lab space # # lay grid into the Lab space # lower = 1 while ((nrcol+2) > lower^3) lower = lower + 1 valseq = seq(0,1,length.out = lower) spl = get.permutations(length(valseq),3,valseq) spl[,1] = spl[,1]*100 spl[,2:3] = (spl[,2:3]*2 - 1)*150 # The nonlinear relations for L, a, and b are intended to mimic the nonlinear response of the eye. Furthermore, uniform changes of components in the Lab color space aim to correspond to uniform changes in perceived color, so the relative perceptual differences between any two colors in Lab can be approximated by treating each color as a point in a three dimensional space and taking the Euclidean distance between them # # tristimulus values of the reference white point: standard light source (D65) chosen according to 6500K color temperature (average daylight) # x = 0.312713 y = 0.329016 z = 1-x-y xn = x/y yn = 1 zn = z/y # conversion of Lab coordinates into XYZ ### sqfkt = function(x){if (x > 6/29)return(x^3) else return(3*(6/29)^2*(x - (4/29)))} xyzspl = apply(t(spl),2,function(x){X = xn*sqfkt((x[1] + 16)/116 + x[2]/500);Y = yn*sqfkt((x[1] + 16)/116);Z = zn*sqfkt((x[1] + 16)/116 - x[3]/200);return(c(X,Y,Z))}) # conversion of XYZ coordinates into RGB (sRGB D65) ### rgb2xyz = matrix(data = c(0.4124564, 0.3575761, 0.1804375, 0.2126729, 0.7151522, 0.0721750, 0.0193339, 0.1191920, 0.9503041),nrow = 3,ncol = 3,byrow = TRUE) linrgbspl = solve(rgb2xyz)%*%xyzspl # adjust for numerical instability # linrgbspl = apply(linrgbspl,c(1,2),function(x){if (x>1){return(1)} else if (x<0){return(0)} else return(x)}) # reverse linearization in RGB # revrgbspl = t(apply(linrgbspl,c(1,2),function(x){if (x <= 0.0031308)return(x*12.92) else return(x^(1/2.4)*(1 + 0.055) - 0.055)})*255) # remove black and white # revrgbspl = revrgbspl[-which(apply(round(revrgbspl),1,sum) %in% c(0,3*255)),] # sample nrcol of colors needed # revrgbspl = revrgbspl[sample(nrow(revrgbspl),nrcol),,drop=FALSE] # conversion to hexadecimal color code # colpal = apply(revrgbspl,1,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) # black and white? # if (!bw){colpal[1] = "#000000";colpal[length(colpal)] = "#FFFFFF"} } else if (method == "goldenratio"){ # 'goldenratio' uses the golden ratio as spacing between colors in the HSV color space # # use random start value # h = runif(1) # subsequently add the golden ratio conjugate (1/golden ratio) modulo 1 # for (i in 1:(nrcol-1)){h = c(h,(h[length(h)] + 0.618033988749895)%%1)} # conversion to hexadecimal color code # colpal = hsv(h = h,s = 1,v = 1) # black and white? # if (!bw){colpal[1] = "#000000";colpal[length(colpal)] = "#FFFFFF"} # method switch trap # } else {stop("method need to be 'RGB', 'Lab' or 'goldenratio' !")} # plot results? # if (show){ if (simulate){ nrcolpal = 4 plot(1,1,xlim=c(0,nrcol),ylim=c(0,nrcolpal*2),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") rect(xleft = 0:(nrcol - 1),ybottom = 1 - 1,xright = 1:nrcol,ytop = 1 - 0.2,col = daltonize(colpal,cvd = "t",show = FALSE)$simulated,border = NA) rect(xleft = 0,ybottom = 1 - 1,xright = nrcol,ytop = 1 - 0.2,col = "transparent",border = "darkgrey") rect(xleft = 0:(nrcol - 1),ybottom = 3 - 1,xright = 1:nrcol,ytop = 3 - 0.2,col = daltonize(colpal,cvd = "d",show = FALSE)$simulated,border = NA) rect(xleft = 0,ybottom = 3 - 1,xright = nrcol,ytop = 3 - 0.2,col = "transparent",border = "darkgrey") rect(xleft = 0:(nrcol - 1),ybottom = 5 - 1,xright = 1:nrcol,ytop = 5 - 0.2,col = daltonize(colpal,cvd = "p",show = FALSE)$simulated,border = NA) rect(xleft = 0,ybottom = 5 - 1,xright = nrcol,ytop = 5 - 0.2,col = "transparent",border = "darkgrey") rect(xleft = 0:(nrcol - 1),ybottom = 7 - 1,xright = 1:nrcol,ytop = 7 - 0.2,col = colpal,border = NA) rect(xleft = 0,ybottom = 7 - 1,xright = nrcol,ytop = 7 - 0.2,col = "transparent",border = "darkgrey") text(rep(nrcol/2,nrcolpal),c(8,6,4,2)-0.6,labels = c(paste("Original colors"),paste("Simulated colors as seen by protanope individuals"),paste("Simulated colors as seen by deuteranope individuals"),paste("Simulated colors as seen by tritanope individuals"))) mtext(paste("distinctcolors"),3,2,cex=1.25) mtext(paste("( ",paste(colpal,collapse = " ")," )"),3,0,col="darkgrey",cex=1 + ((1-0.25)*(nchar(paste("( ",paste(colpal,collapse = " ")," )"))-50))/(50-185)) } else { plot(1,1,xlim=c(0,nrcol),ylim=c(0,8),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") rect(xleft = 0:(nrcol - 1),ybottom = 3,xright = 1:nrcol,ytop = 5,col = colpal,border = NA) rect(xleft = 0,ybottom = 3,xright = nrcol,ytop = 5,col = "transparent",border = "darkgrey") mtext(paste("distinctcolors"),3,2,cex=1.25) mtext(paste("( ",paste(colpal,collapse = " ")," )"),3,0,col="darkgrey",cex=1 + ((1-0.25)*(nchar(paste("( ",paste(colpal,collapse = " ")," )"))-50))/(50-185)) } } # return colpal # return(colpal) } # alias # LSD.distinctcolors = distinctcolors ### convertcolor ### #' @export #' @name convertcolor #' @aliases LSD.convertcolor #' @title Map R colors to hexadecimal representation #' @description Convert R built-in colors to hexadecimal representation. #' @param cols a character vector containing R built-in colors. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @return \code{convertcolor} returns a vector containing R built-in colors in hexadecimal representation. #' @author Bjoern Schwalb #' @seealso \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} #' @examples convertcolor(c("red","green","blue")) #' @keywords color convertcolor = function(cols,alpha = NULL) { colmat = col2rgb(cols) cols = apply(colmat,2,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) if (!is.null(alpha)){cols = paste(cols,alpha,sep="")} return(cols) } # alias # LSD.convertcolor = convertcolor ### complementarycolor ### #' @export #' @name complementarycolor #' @aliases LSD.complementarycolor #' @title Complement R colors #' @description Convert R built-in colors to their color complement #' @param cols a character vector containing R built-in colors. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @return \code{complementarycolor} returns a vector containing R built-in colors in hexadecimal representation. #' @author Bjoern Schwalb #' @seealso \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} #' @examples complementarycolor(c("red","green","blue")) #' @keywords color complementarycolor = function(cols,alpha = NULL) { colmat = c(255,255,255) - col2rgb(cols) cols = apply(colmat,2,function(x){rgb(x[1],x[2],x[3],maxColorValue = 255)}) if (!is.null(alpha)){cols = paste(cols,alpha,sep="")} return(cols) } # alias # LSD.complementarycolor = complementarycolor ### convertgrey ### #' @export #' @name convertgrey #' @aliases LSD.convertgrey #' @title Convert R colors to greyscale #' @description Greyscale R built-in colors. #' @param cols a character vector containing R built-in colors. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @return \code{convertgrey} returns a vector containing R built-in colors in hexadecimal representation. #' @author Bjoern Schwalb #' @seealso \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{demotour}} #' @examples convertgrey(c("red","green","blue")) #' @keywords greyscale color convertgrey = function(cols,alpha = NULL) { colmat = col2rgb(cols) cols = apply(colmat,2,function(x){rgb(0.3*x[1]+0.59*x[2]+0.11*x[3],0.3*x[1]+0.59*x[2]+0.11*x[3],0.3*x[1]+0.59*x[2]+0.11*x[3],maxColorValue = 255)}) if (!is.null(alpha)){cols = paste(cols,alpha,sep="")} return(cols) } # alias # LSD.convertgrey = convertgrey LSD/R/LSD.clusterplot.R0000755000176200001440000003027512453270442014236 0ustar liggesusers ### singleclusterplot ### #' @export #' @name singleclusterplot #' @aliases LSD.singleclusterplot #' @title Visualize two-dimensional data clusters (add to an existing plot) #' @description Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion (add to an existing plot). #' @param input matrix or list with numerical entries. #' @param at a integer vector containing the x-positions corresponding to the columns of 'input'. #' @param fromto a numeric vector containing the range of quantiles (between 0 and 1) to be plotted. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified). #' @param outer.col R built-in color to be used for outlier lines (lines outside of 'fromto'). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param quartiles.col a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')). #' @param add.quartiles logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{clusterplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples samples = 100 #' probes = 200 #' clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) #' #' clus = rbind( #' t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples, #' t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) #' #' emptyplot(xlim = c(1,ncol(clus)),ylim = range(clus)) #' singleclusterplot(clus) #' axis(1) #' axis(2) #' box() #' @keywords cluster singleclusterplot = function(input,at = NULL,fromto = c(0.05,0.95),colpal = "standardheat",simulate = FALSE,daltonize = FALSE,cvd = "p",nrcol = 25,outer.col = "lightgrey",rev = FALSE,alpha = NULL,quartiles.col = c("grey","black","grey"),add.quartiles = TRUE) { # stops execution, if 'input' is neither a list nor a matrix and executes an error action # if (!is.matrix(input) & !is.list(input)) stop("'input' must be a matrix or a list !") # define x-positions corresponding to the columns/elements of 'input' # if (is.null(at)) if (is.matrix(input)){at=1:ncol(input)} else if (is.list(input)){at=1:length(input)} # preliminaries # probes = length(at) # wrapper for the lines function # drawline = function(y,col="black",lwd=1,lty=1){lines(at[1:length(y)],y,type="l",col=col,lwd=lwd,lty=lty)} # optional drawing of outlier lines # if (is.matrix(input)){if (outer.col!="none") apply(input,1,drawline,col=outer.col)} # provide 'colpal' via colorpalette # colpal = colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev) colpal = c(rev(colpal),colpal) # determine quantiles among columns/elements of 'input' # if (is.matrix(input)){ qline = apply(input,2,quantile,probs=seq(fromto[1],fromto[2],length=(length(colpal)+1)),na.rm=TRUE) } else if (is.list(input)){ qline = lapply(input,quantile,probs=seq(fromto[1],fromto[2],length=(length(colpal)+1)),na.rm=TRUE) qline = sapply(qline,c) } # plot polygons according to qline # for (j in 1:length(colpal)){polygon(at[c(1:probes,probes:1)],c(qline[j,],qline[j+1,probes:1]),col = colpal[j],lty=0)} # add lines corresponding to the quartiles # if (add.quartiles){ if (is.matrix(input)){ drawline(apply(input,2,quantile,probs=0.5,na.rm=TRUE),col=quartiles.col[2],lwd=2) drawline(apply(input,2,quantile,probs=0.25,na.rm=TRUE),col=quartiles.col[1],lwd=2) drawline(apply(input,2,quantile,probs=0.75,na.rm=TRUE),col=quartiles.col[3],lwd=2) } else if (is.list(input)){ drawline(sapply(input,quantile,probs=0.5,na.rm=TRUE),col=quartiles.col[2],lwd=2) drawline(sapply(input,quantile,probs=0.25,na.rm=TRUE),col=quartiles.col[1],lwd=2) drawline(sapply(input,quantile,probs=0.75,na.rm=TRUE),col=quartiles.col[3],lwd=2) } } } # alias # LSD.singleclusterplot = singleclusterplot ### clusterplot ### #' @export #' @name clusterplot #' @aliases LSD.clusterplot #' @title Visualize two-dimensional data clusters #' @description Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion. #' @param input matrix or list with numerical entries. #' @param label a character vector assigning rows/elements of 'input' to clusters (if specified, multiple clusters can be depicted in different colors and/or subsequent plots). #' @param at a integer vector containing the x-positions corresponding to the columns of 'input'. #' @param main title(s) of the plot, standard graphics parameter. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param xlabels a character vector containing labels for the x-axis. #' @param fromto a numeric vector containing the range of quantiles (between 0 and 1) to be plotted. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified). #' @param outer.col R built-in color to be used for outlier lines (lines outside of 'fromto'). #' @param quartiles.col a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')). #' @param add.quartiles logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles. #' @param separate if \code{TRUE} (by default), different clusters are depicted in subsequent plots. #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param size logical: if \code{TRUE} (by default), the size of each cluster is added to the title of the respective plot. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param axes logical: if \code{TRUE} (by default), a box and axes are added to the plot (if \code{FALSE}, custom specification of axes can be achieved via basic R graphics functions). #' @param ... additional parameters to be passed to points and plot. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{singleclusterplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples samples = 100 #' probes = 75 #' at = 1:probes #' clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) #' #' clus = rbind( #' t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples, #' t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) #' #' quartiles.col = c("transparent","black","transparent") #' colpal = c("standardheat","crazyblue","crazyred","crazygreen") #' #' labs = paste("cluster",kmeans(clus,4)$cluster) #' clusterplot(clus,fromto=c(0,1)) #' #' clusterplot(clus,labs,separate=FALSE,xaxt="n",fromto=c(0.4,0.6),colpal=colpal, #' outer.col="none",ylim=c(-2,3),quartiles.col = quartiles.col) #' #' clusterplot(clus,labs,colpal=colpal) #' #' labs = paste("cluster",kmeans(clus,2)$cluster) #' colpal = c("greens","purples") #' clusterplot(clus,labs,separate=FALSE,xaxt="n",fromto=c(0.3,0.7),colpal=colpal, #' outer.col="none",ylim=c(-1,2),alpha=50,quartiles.col = quartiles.col) #' @keywords cluster clusterplot = function(input,label = NULL,at = NULL,main = NULL,xlim = NULL,ylim = NULL,xlabels = NULL,fromto = c(0.05,0.95),colpal = "standardheat",simulate = FALSE,daltonize = FALSE,cvd = "p",nrcol = 25,outer.col = "lightgrey",quartiles.col = c("grey","black","grey"),add.quartiles = TRUE,separate = TRUE,rev = FALSE,size = TRUE,alpha = NULL,axes = TRUE,...) { # stops execution, if 'input' is neither a list nor a matrix and executes an error action # if (!is.matrix(input) & !is.list(input)) stop("'input' must be a matrix or a list !") # define x-positions corresponding to the columns of 'input' # if (is.null(at)) if (is.matrix(input)){at=1:ncol(input)} else if (is.list(input)){at=1:length(input)} # preliminaries # probes = length(at) if (is.null(xlim)){xlim=c(min(at),max(at))} maxp = xlim[2] minp = xlim[1] if (is.null(ylim)) if (is.matrix(input)){ylim=c(min(input,na.rm=TRUE),max(input,na.rm=TRUE))} else if (is.list(input)){ylim=c(min(unlist(input),na.rm=TRUE),max(unlist(input),na.rm=TRUE))} if (is.null(xlabels)) xlabels = 1:length(at) # one cluster (i.e. one plot), if label = NULL # if (is.null(label)){ plot.new() plot.window(xlim = xlim,ylim = ylim,...) if (size){ if (is.matrix(input)){ main = paste(main," ( #",nrow(input)," )") } else if (is.list(input)){ input.length.range = range(as.numeric(summary(input)[,"Length"])) main = paste(main," ( #",input.length.range[1],"-",input.length.range[2]," )") } } title(main) if (axes){ axis(1,at=at,labels=xlabels,...) axis(2) box() } singleclusterplot(input=input,at=at,fromto=fromto,colpal=colpal,simulate=simulate,daltonize=daltonize,cvd=cvd,nrcol=nrcol,outer.col=outer.col,add.quartiles=add.quartiles,quartiles.col=quartiles.col,rev=rev,alpha=alpha) } # multiple clusters, if label is specified # if (!is.null(label)) { clusternames = sort(unique(label)) nrclusters = length(clusternames) if (!is.matrix(input)) stop("'input' must be a matrix, if 'label' is specified !") clustersets = split(1:nrow(input), factor(label)) if (!is.list(colpal)) colpal = as.list(colpal) if (length(colpal) < nrclusters) colpal = rep(colpal, nrclusters) # multiple clusters in one plots # if (separate == FALSE){ plot.new() plot.window(xlim = xlim,ylim = ylim,...) if (size){main = paste(main," ( #",nrow(input)," )")} title(main) if (axes){ axis(1,at=at,labels=xlabels,...) axis(2) box() } } # multiple clusters in subsequent plots # if (separate == TRUE) par(mfrow = windowxy(nrclusters)) for (j in seq(clusternames)){ if (separate == TRUE){ if (length(main) == length(clustersets[[j]])) clustermain = main[j] else clustermain = paste(main,clusternames[j]) plot.new() plot.window(xlim = xlim,ylim = ylim,...) if (size){clustermain = paste(clustermain," ( #",length(clustersets[[j]])," )")} title(clustermain) if (axes){ axis(1,at=at,labels=xlabels,...) axis(2) box() } } singleclusterplot(input=input[clustersets[[j]],,drop = FALSE],at=at,fromto=fromto,colpal=colpal[[j]],simulate=simulate,daltonize=daltonize,cvd=cvd,nrcol=nrcol,outer.col=outer.col,add.quartiles=add.quartiles,quartiles.col=quartiles.col,rev=rev,alpha=alpha) } } } # alias # LSD.clusterplot = clusterplot LSD/R/LSD.ellipsescatter.R0000755000176200001440000000656212453265421014704 0ustar liggesusers ### ellipsescatter ### #' @export #' @name ellipsescatter #' @aliases LSD.ellipsescatter #' @title Visualize subgroups of two-dimensional data assuming normal distributions #' @description A scatterplot with additional colored ellipses based on a gaussianity assumption. #' @param x a numeric vector. #' @param y a numeric vector. #' @param groups a list of indices or vector names to be plotted as groups (not necessarily all of x and y). #' @param colors a character vector of R build-in colors corresponding to the chosen groups. #' @param pch the plotting character (to be passed to plot). #' @param bgcol a R build-in color for non-grouped points. #' @param main title(s) of the plot, standard graphics parameter. #' @param xlab x label, standard graphics parameter. #' @param ylab y label, standard graphics parameter. #' @param scalesd a numeric value giving the scaling factor for standard deviations in each dimension (defaults to 1). #' @param level a numeric value (between 0 and 1) giving the confidence level of a pairwise confidence region. #' @param legend.cex a numerical value giving the amount by which the added legend should be magnified relative to the default. #' @param location the x and y co-ordinates to be used to position the legend (see 'xy.coords'). #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples x = c(rnorm(50),rnorm(100,2),rnorm(50,4)) #' y = (x + rnorm(200,0,0.8))*rep(c(1,4,1),c(50,100,50)) #' x = sign(x)*abs(x)^1.3 #' #' groups = list("Green" = 1:50,"Red" = 51:150,"Blue" = 151:200) #' colors = c("darkgreen","darkred","darkblue") #' ellipsescatter(x,y,groups,colors,location = "topleft") #' @keywords scatterplot ellipsescatter = function(x,y,groups,colors = NULL,pch = 20,bgcol = "darkgrey",main = "ellipsescatter",xlab = NULL,ylab = NULL,scalesd = 1,level = 0.75,legend.cex = 1,location = "topright",...) { if(is.null(names(groups))){names(groups) = 1:dim(summary(groups))[1]} grouplength = length(names(groups)) if(is.null(colors)){colors = 1:grouplength} ellipse.coordinates = function(r,scale = c(1,1),centre = c(0,0),level = 0.95,t = sqrt(qchisq(level,2))) { r = min(max(r,-1),1) d = acos(r) a = seq(0,2*pi,len = 100) matrix(c(t*scale[1]*cos(a + d/2) + centre[1],t*scale[2]*cos(a - d/2) + centre[2]),100,2,dimnames = list(NULL,c("x","y"))) } add.ellipses = function(x,y,col) { points(x,y,col=col,pch=pch) points(ellipse.coordinates(round(cor(x,y,method="spearman",use="na.or.complete"),digits=2),scale=c(sd(x,na.rm=TRUE)*scalesd,sd(y,na.rm=TRUE)*scalesd),centre=c(mean(x,na.rm=TRUE),mean(y,na.rm=TRUE)),level=level),type = 'l',col=col,lwd=3) } if (is.null(xlab)){xlab = deparse(substitute(x))} if (is.null(ylab)){ylab = deparse(substitute(y))} plot(x,y,pch=pch,col=bgcol,ylab = ylab,xlab = xlab,main="",...) mtext(paste(main),3,2,cex=1.25) legendtext = c() for (k in 1:grouplength){ add.ellipses(x[groups[[k]]],y[groups[[k]]],col=colors[k]) legendtext = c(legendtext,paste(names(groups)[k]," (",length(x[groups[[k]]][!is.na(x[groups[[k]]])]),")",sep="")) } legend(location,legendtext,pt.bg=colors,col=rep("black",grouplength),bg="white",pch=21,cex=legend.cex,inset=0.01) } ### aliases ### LSD.ellipsescatter = ellipsescatter LSD/R/LSD.linesplot.r0000755000176200001440000000664112452755662013742 0ustar liggesusers ### linesplot ### #' @export #' @name linesplot #' @aliases LSD.linesplot #' @title One-dimensional scatterplot #' @description Visualize one-dimensional data in its every detail. #' @param x numeric data as vector, matrix, list or data.frame. #' @param labels a character vector of labels. #' @param col a R build-in color. #' @param cols a character vector of R build-in colors. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param xlab x label, standard graphics parameter. #' @param ylab y label, standard graphics parameter. #' @param las las=1: horizontal text, las=2: vertical text (x-axis labels). #' @param outline logical: if \code{TRUE} (by default), outliers are plotted. #' @param cexbox a numerical value giving the amount by which the boxes should be magnified relative to the default. #' @param addboxes logical: if \code{TRUE} (\code{FALSE} by default), boxplots be added to the plot. #' @param border a R build-in color for the box and the whiskers (if \code{addboxes = TRUE}). #' @param range this determines how far the plot whiskers extend out from the box. #' @param lwd linewidth of the box and whiskers. #' @param main title(s) of the plot, standard graphics parameter. #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples l = list() #' for (i in 1:10){l[[i]] = rnorm(100,sqrt(i^2.5),1+i/2)} #' #' linesplot(l,alpha=25,border="darkred",addboxes = TRUE,outline=FALSE) #' @keywords boxplotlike linesplot = function(x,labels = NULL,col = "black",cols = NULL,alpha = 25,xlim = NULL,ylim = NULL,xlab = NULL,ylab = "",las = 1,outline = TRUE,cexbox = 0.6,addboxes = FALSE,border = "black",range = 1.5,lwd = 1.5,main = "LSD.linesplot",...) { if (!is.vector(x) & !is.matrix(x) & !is.list(x) & !is.data.frame(x)) stop("x must be a vector, matrix, list or a data.frame!") if (!is.list(x) & !is.matrix(x) & !is.data.frame(x)){x = cbind(x)} if (is.data.frame(x)){x = as.list(x)} if (is.matrix(x)){x = as.list(as.data.frame(x))} if (is.null(labels)){labels = labels(x)} if (is.null(cols)){cols = rep(convertcolor(col,alpha),length(x))} else{cols = convertcolor(cols,alpha)} if (!is.null(xlim)){print("xlim argument will be ignored!")} if (is.null(ylim)){ylim = range(unlist(x),na.rm=TRUE)} if (!is.null(xlab)){print("xlab argument will be ignored! Use labels instead!")} if (length(x) == 1){cexbox = 0.4} if (length(x) > 1){boxwex = cexbox} else{boxwex = NULL} plot(1,col="white",xlim=c(0.5,length(x)+0.5),ylim=ylim,xlab="",xaxt="n",ylab=ylab,main="",...) mtext(paste(main),3,2,cex=1.25) par.axis.default = par("cex.axis") par(cex.axis = par("cex.lab")) axis(1,at=seq(1,length(x),1),labels=labels,las=las) for (j in 1:length(x)){segments(j-cexbox/2,x[[j]],j+cexbox/2,x[[j]],lwd=2,col=cols[j])} if (addboxes){boxplot(x,add=TRUE,col="transparent",xlim=c(0.5,length(x)+0.5),ylim=ylim,width=NULL,boxwex=boxwex,outline=outline,axes=FALSE,border=border,lwd=lwd,range=range)} par(cex.axis = par.axis.default) } ### aliases ### LSD.linesplot = linesplot LSD/R/LSD.demotour.R0000755000176200001440000002210113672346616013514 0ustar liggesusers ### demotour ### #' @export #' @name demotour #' @aliases LSD.demotour #' @title LSD teaser #' @description A compilation of selected plot examples. #' @author Bjoern Schwalb #' @seealso \code{\link{heatscatter}}, \code{\link{clusterplot}}, \code{\link{disco}}, \code{\link{colorpalette}}, \code{\link{daltonize}} #' @examples demotour() #' @keywords heatscatter clusterplot disco colorpalette daltonize demotour = function() { # LSD.show # LSD.show = function(it){ emptyplot() text(-0.7,0.15,it,pos=4,cex=pmax(1,6-log(nchar(it)))) points(-0.7,0,pch=3,cex=8,col="red") } # heatscatter # par(mfrow=c(1,1)) LSD.show("heatscatter") devAskNewPage(ask = TRUE) points = 10^4 x = c(rnorm(points/2),rnorm(points/2)+4) y = x + rnorm(points,sd=0.8) x = sign(x)*abs(x)^1.3 par(mfrow=c(2,2)) heatscatter(x,y) heatscatter(x,y,colpal="bl2gr2rd",main="bl2gr2rd") heatscatter(x,y,main="greyscales with add.contour=TRUE",add.contour=TRUE,color.contour="red",greyscale=TRUE) heatscatter(x,y,colpal="spectral",main="spectral with add.contour=TRUE",add.contour=TRUE) devAskNewPage(ask = TRUE) # clusterplot # par(mfrow=c(1,1)) LSD.show("clusterplot") devAskNewPage(ask = TRUE) samples = 150 probes = 75 at = 1:probes clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) clus = rbind(t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples,t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) labs = paste("cluster",kmeans(clus,4)$cluster) par(mfrow=c(2,2)) clusterplot(clus,label=labs,main="Data",colpal=c("standardheat","crazyblue","crazyred","standardtopo")) devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) clusterplot(clus,label=paste("cluster",kmeans(clus,2)$cluster),separate=FALSE,main="Alpha overlay",fromto=c(0.3,0.7),colpal=c("greens","purples"),outer.col="none",ylim=c(-1,2),alpha=50,quartiles.col = c("transparent","black","transparent")) devAskNewPage(ask = TRUE) # daltonize # par(mfrow=c(1,1)) LSD.show("daltonize") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) daltonize("rdylgn",cvd = "d") devAskNewPage(ask = TRUE) ### disco ### nrcol = 11 par(mfrow=c(1,1)) LSD.show("disco") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) ownpals = c("colorblind","standard","crazyred","crazygreen","crazyblue","girly","jamaica","mountain","heat") pals = ownpals npal = length(ownpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the LSD package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) brewerpals = c("spectral","rdylgn","rdylbu","rdgy","rdbu","puor","prgn","piyg","brbg") pals = brewerpals npal = length(brewerpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the RColorBrewer package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) brewerpals = c("ylorrd","ylorbr","ylgnbu","ylgn","reds","rdpu","purples","purd","pubugn","pubu","orrd","oranges","greys","greens","gnbu","bupu","bugn","blues") pals = brewerpals npal = length(brewerpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the RColorBrewer package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) rampspals = c("bl2gr","bl2gr2rd","bl2rd","bl2yl","cy2yl","gr2rd","ma2gr","matlablike","matlablike2") pals = rampspals npal = length(rampspals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the colorRamps package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) grpals = c("standardterrain","standardtopo","standardheat","standardrainbow","standardcm") pals = grpals npal = length(grpals) plot(1,1,xlim=c(0,nrcol),ylim=c(0,npal),type="n",axes=FALSE,bty="n",xlab="",ylab="",main="") for (i in 1:npal){rect(xleft = 0:(nrcol - 1),ybottom = i - 1,xright = 1:nrcol,ytop = i - 0.2,col = colorpalette(pals[i],nrcol),border = NA)} for (i in 1:npal){rect(xleft = 0,ybottom = i - 1,xright = nrcol,ytop = i - 0.2,col = "transparent",border = "darkgrey")} text(rep(-0.1,npal),(1:npal)-0.6,labels = pals,xpd = TRUE,adj = 1,cex=0.8) mtext(paste("palettes from the grDevices package"),3,2,cex=1.25) mtext(paste("( character strings can be passed to LSD functions as 'colpal' )"),3,0,col="darkgrey") # heatboxplot # par(mfrow=c(1,1)) LSD.show("heatboxplot") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) f = c(rnorm(200),rnorm(200)+4) h = rf(500,15,15)*10 g = rnorm(300)+1 heatboxplot(list(f=f,g=g),colpals=c("rdpu","greens"),labels=c("bimodal","unimodal")) devAskNewPage(ask = TRUE) # intersphere # par(mfrow=c(1,1)) LSD.show("intersphere") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) data = list("A" = sample(1:200,100),"B" = sample(1:200,150),"C" = sample(1:200,50),"D" = sample(1:200,75)) intersphere(data,colors = c("orange","skyblue","green","purple"),expand.circles = 0.5,expand.lims = 0.5) devAskNewPage(ask = TRUE) # align # homer = list() homer[[1]] = c(0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) homer[[2]] = c(0,0,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0) homer[[3]] = c(0,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0) homer[[4]] = c(1,0,1,1,1,2,2,2,2,2,2,1,1,0,0,0,0,0,0,0,0,0) homer[[5]] = c(1,0,1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0,0,0) homer[[6]] = c(0,1,2,1,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0,0) homer[[7]] = c(0,1,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0,0) homer[[8]] = c(1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,0,0,0,0,0) homer[[9]] = c(1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,0,0,0,0) homer[[10]] = c(1,2,2,2,2,2,2,2,2,2,1,1,1,1,1,0,0,0,1,0,0,0) homer[[11]] = c(1,2,2,2,2,2,2,2,2,1,0,0,0,0,1,0,0,0,0,1,0,0) homer[[12]] = c(1,2,2,2,2,2,2,2,1,0,0,0,0,0,0,1,0,1,0,1,0,0) homer[[13]] = c(1,2,2,2,2,2,2,2,1,0,0,0,0,0,0,1,0,0,0,1,0,0) homer[[14]] = c(0,1,2,2,1,2,2,2,1,0,0,0,1,0,0,1,1,1,1,0,0,0) homer[[15]] = c(0,1,2,2,1,1,2,2,2,1,0,0,0,0,1,2,2,2,2,1,0,0) homer[[16]] = c(0,1,1,1,2,2,1,2,2,2,1,1,1,1,2,2,2,2,2,1,0,0) homer[[17]] = c(0,1,0,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,0,0,0) homer[[18]] = c(0,0,0,1,1,1,2,2,2,2,2,2,1,1,1,3,3,3,3,1,0,0) homer[[19]] = c(0,0,0,1,2,2,2,2,2,2,2,1,3,3,3,3,3,3,3,3,1,0) homer[[20]] = c(0,0,0,1,2,2,1,2,2,2,1,3,3,3,3,3,3,3,3,3,1,0) homer[[21]] = c(0,0,0,0,1,1,2,2,2,1,3,3,3,3,3,3,3,3,3,3,3,1) homer[[22]] = c(0,0,0,0,0,1,2,2,2,1,3,1,3,3,3,3,3,3,3,3,3,1) homer[[23]] = c(0,0,0,0,0,1,2,2,2,1,3,1,1,1,1,1,1,1,1,1,1,0) homer[[24]] = c(0,0,0,0,0,1,2,2,2,1,3,3,3,3,3,3,3,1,0,0,0,0) homer[[25]] = c(0,0,0,0,0,1,2,2,2,2,1,3,3,3,3,3,1,0,0,0,0,0) homer[[26]] = c(0,0,0,0,0,1,2,2,2,2,1,3,3,3,3,3,1,0,0,0,0,0) homer[[27]] = c(0,0,0,0,1,1,2,2,2,2,2,1,3,3,3,1,0,0,0,0,0,0) homer[[28]] = c(0,0,0,1,0,0,1,1,2,2,2,2,1,1,1,1,1,0,0,0,0,0) homer[[29]] = c(0,0,0,1,0,0,0,0,1,1,2,2,2,2,2,1,0,1,0,0,0,0) homer[[30]] = c(0,0,1,1,0,0,0,0,0,0,1,1,2,2,2,1,0,0,1,1,0,0) homer[[31]] = c(0,1,0,0,1,0,0,0,0,0,0,1,1,2,2,1,0,0,0,1,0,0) par(mfrow=c(1,1)) LSD.show("align") devAskNewPage(ask = TRUE) par(mfrow=c(1,1)) align(homer,colpal = c("white","black","yellow","wheat3"),main = "D'OH!",asp = 1,axes = FALSE) devAskNewPage(ask = TRUE) # and many more ... # par(mfrow=c(1,1)) LSD.show("and many more ...") } ### aliases ### LSD.demotour = demotour LSD/R/LSD.comparisonplot.r0000755000176200001440000002232713672347063014776 0ustar liggesusers ### heatbarplot ### #' @export #' @name heatbarplot #' @aliases LSD.heatbarplot #' @title Color a barplot. #' @description Depict a histogram object as a barplot in a color encoded fashion based on a kernel density estimate. #' @param x a histogram object. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param horizontal logical: if \code{TRUE} (\code{FALSE} by default), rotation of 90 degrees is applied. #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples points = 10^4 #' x = c(rnorm(points/2),rnorm(points/2)+4) #' x = sign(x)*abs(x)^1.3 #' xhist = hist(x,plot = FALSE) #' #' heatbarplot(xhist) #' @keywords barplot heatbarplot = function(x,colpal = "heat",simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,rev = FALSE,horizontal = FALSE,nrcol = 100,...) { if (class(x) != "histogram") stop("x must be of class histogram!") if (!horizontal){ barplot(x$density,axes = FALSE,space = 0,border = "white",...) dy = (max(x$density) - 0)/nrcol colpal = colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev) colorlane = function(a,b){for(i in 1:100){rect(a,0 + (i-1) * dy,b,0 + i*dy,col = colpal[i],border = NA)}} for (j in 1:length(x$counts)){colorlane(j-1,j)} for (j in 1:length(x$counts)){rect(j-1,x$density[j],j,max(x$density),col = "white",border = NA)} for (j in 1:length(x$counts)){rect(j-1,0,j,x$density[j],col = "transparent",border = NULL)} } else{ barplot(x$density,axes = FALSE,space = 0,border = "white",horiz=TRUE,...) dy = (max(x$density) - 0)/nrcol colpal = colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev) colorlane = function(a,b){for(i in 1:100){rect(0 + (i-1) * dy,a,0 + i*dy,b,col = colpal[i],border = NA)}} for (j in 1:length(x$counts)){colorlane(j-1,j)} for (j in 1:length(x$counts)){rect(x$density[j],j-1,max(x$density),j,col = "white",border = NA)} for (j in 1:length(x$counts)){rect(0,j-1,x$density[j],j,col = "transparent",border = NULL)}} } ### aliases ### LSD.heatbarplot = heatbarplot ### comparisonplot ### #' @export #' @name comparisonplot #' @aliases cplot #' @title Comparisonplot: a fancy scatterplot #' @description A function to compare two vectors extensively. #' @param x a numeric vector. #' @param y a numeric vector. #' @param histbreaks a non-negative integer specifying the number of breaks of the histograms. #' @param adjust scale the used bandwidth of the density estimate, if \code{add.density = TRUE}. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param main title(s) of the plot, standard graphics parameter. #' @param cor if \code{TRUE} (\code{FALSE} by default), the correlation is added to the title. #' @param xlab x label, standard graphics parameter. #' @param ylab y label, standard graphics parameter. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param ab if \code{TRUE} (\code{FALSE} by default), \code{abline(0,1)} is added to the heatscatter. #' @param add.density if \code{TRUE} (\code{FALSE} by default), density lines are added to the barplots. #' @param col.density R built-in color to specify the color of the density line. #' @param pimp if \code{TRUE} (\code{FALSE} by default), the plot is pimped. #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples points = 10^4 #' x = c(rnorm(points/2),rnorm(points/2)+4) #' y = x + rnorm(points,sd=0.8) #' x = sign(x)*abs(x)^1.3 #' #' comparisonplot(x,y,histbreaks=30,pch=20) #' @keywords scatterplot barplot comparisonplot = function(x,y,histbreaks = 30,adjust = 1,colpal = "heat",simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,rev = FALSE,main = "comparisonplot",cor = FALSE,xlab = NULL,ylab = NULL,xlim = NULL,ylim = NULL,ab = FALSE,add.density = FALSE,col.density = "darkred",pimp = FALSE,...) { if (!is.vector(x) | !is.vector(y)) stop("First two argument must be vectors!") if (is.null(xlab)){xlab = deparse(substitute(x))} if (is.null(ylab)){ylab = deparse(substitute(y))} sound = which((!(is.na(x)|is.nan(x)|(x==Inf)|(x==-Inf))) & (!(is.na(y)|is.nan(y)|(y==Inf)|(y==-Inf)))) if (length(sound)==0) stop("There are no valid point pairs to plot!") x = x[sound] y = y[sound] xrange <- c(min(range(x),range(y)),max(range(x),range(y))) yrange <- c(min(range(x),range(y)),max(range(x),range(y))) if (!is.null(xlim)){cut = x > xlim[1] & x < xlim[2] x = x[cut] y = y[cut] xrange = xlim } if (!is.null(ylim)){cut = y > ylim[1] & y < ylim[2] y = y[cut] x = x[cut] yrange = ylim } def.par = par(no.readonly = TRUE) # save default, for resetting... xhist = hist(x, breaks=seq(xrange[1],xrange[2],length.out=histbreaks),plot=FALSE) yhist = hist(y, breaks=seq(yrange[1],yrange[2],length.out=histbreaks),plot=FALSE) top = max(c(xhist$density,yhist$density)) nf = layout(matrix(c(0,2,0,4,1,3,0,5,0),3,3,byrow=TRUE), c(1,3,1), c(1,3,1), TRUE) dx = density(x) dy = density(y) par(mar=c(4,4,4,4)) heatscatter(x,y,xlim=xrange,ylim=yrange,xlab = xlab,ylab = ylab,main=main,colpal=colpal,cor=cor,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev,...) if (pimp){ if (ab){abline(0,1,col="#08306B50",lwd=2)} par(mar=c(0,4,1,4)) heatbarplot(xhist,ylim=c(0,top),colpal=colpal,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = !rev) if (add.density){lines((dx$x-xhist$breaks[1])/(xhist$breaks[2]-xhist$breaks[1]),dx$y,lwd = 2,col = col.density)} par(mar=c(4,0,4,1)) heatbarplot(yhist,xlim=c(0,top),colpal=colpal,horizontal=TRUE,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = !rev) if (add.density){lines(dy$y,(dy$x-yhist$breaks[1])/(yhist$breaks[2]-yhist$breaks[1]),lwd = 2,col = col.density)} par(mar=c(4,1,4,0)) heatboxplot(y,axes=FALSE,graphics = FALSE,colpal=colpal,ylim=yrange,nolab=TRUE,adjust=adjust,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = !rev) par(mar=c(1,4,0,4)) heatboxplot(x,axes=FALSE,horizontal=TRUE,graphics = FALSE,colpal=colpal,ylim=xrange,nolab=TRUE,adjust=adjust,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = !rev) } else { if (ab){abline(0,1,col="black",lwd=1)} par(mar=c(0,4,1,4)) barplot(xhist$density, axes=FALSE, ylim=c(0, top), space=0,col="#F0F0F0") if (add.density){lines((dx$x-xhist$breaks[1])/(xhist$breaks[2]-xhist$breaks[1]),dx$y,lwd = 2,col = col.density)} par(mar=c(4,0,4,1)) barplot(yhist$density, axes=FALSE, xlim=c(0, top), space=0,col="#F0F0F0", horiz=TRUE) if (add.density){lines(dy$y,(dy$x-yhist$breaks[1])/(yhist$breaks[2]-yhist$breaks[1]),lwd = 2,col = col.density)} par(mar=c(4,1,4,0)) boxplot(y,axes=FALSE,col="#F0F0F0",ylim=yrange) par(mar=c(1,4,0,4)) boxplot(x,axes=FALSE,horizontal=TRUE,col="#F0F0F0",ylim=xrange) } par(def.par) } ### aliases ### LSD.comparisonplot = comparisonplot LSD/R/LSD.plotit.r0000755000176200001440000001203613672357763013244 0ustar liggesusers ### plotit ### #' @export #' @name plotit #' @aliases LSD.plotit #' @title Plotting wrapper function to plot plots in printable quality and all kinds of formats #' @description Plotting wrapper function to save plots in R as "pdf", "ps", "jpeg", "png", "bmp" or "tiff". #' @param filename name of the plot to be saved with the format type suffix. #' @param sw scaling factor of weight. #' @param sh scaling factor of height. #' @param sres scaling factor of the resolution. #' @param plotsfkt list of plots to be plotted. #' @param ww width of window. #' @param wh height of window. #' @param pointsize the default pointsize of plotted text, interpreted as big points (1/72 inch) for plots to be saved. #' @param dev.pointsize pointsize of plotted text, interpreted as big points (1/72 inch) for display in R. #' @param paper needed only if filformat = "pdf" or "ps". #' @param quality needed only if filformat = "jpeg". #' @param units needed only if filformat = "jpeg", "png", "bmp" or "tiff". #' @param bg backgroundcolor. #' @param fileformat save the plot as "pdf", "ps", "jpeg", "png", "bmp" or "tiff". #' @param saveit should plot be saved. #' @param notinR should plot be not plotted in R. #' @param addformat should plot be saved additionally in another format ("pdf", "ps", "jpeg", "png", "bmp" or "tiff"). #' @author Bjoern Schwalb #' @seealso \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples data(homer) #' #' plotsfkt = function(){ #' colpal = c("white","black","yellow","wheat3") #' align(homer,colpal = colpal,main = "D'OH!",asp = 1,axes = FALSE) #' } #' #' # choose 'saveit = TRUE' for saving the plot in the specified fileformat # #' #' # choose 'notinR = TRUE' to suppress plotting in R # #' #' plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "jpeg") #' #' plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "png") #' #' plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "bmp") #' #' plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "tiff") #' #' plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "ps") #' #' plotit("homer",sw = 2,sh = 2,sres = 2,plotsfkt,saveit = FALSE,notinR = FALSE,fileformat = "pdf") #' @keywords plot jpeg png bmp tiff ps pdf plotit = function(filename,sw = 1,sh = 1,sres = 1,plotsfkt,ww = 7,wh = 7,pointsize = 12,dev.pointsize = 8,paper = "special",quality = 100,units = "px",bg = "white",fileformat = "jpeg",saveit = FALSE,notinR = FALSE,addformat = NULL) { # switch between different file formats for plot saving (if saveit = TRUE) # pwidth = sw*480 pheight = sh*480 pres = sres*72 if (saveit){ switch(fileformat,"jpeg" = jpeg(filename = paste(filename,".",fileformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, quality = quality, bg = bg,res = pres), "png" = png(filename = paste(filename,".",fileformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, bg = bg,res = pres), "bmp" = bmp(filename = paste(filename,".",fileformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, bg = bg,res = pres), "tiff" = tiff(filename = paste(filename,".",fileformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, bg = bg,res = pres), "ps" = postscript(file = paste(filename,".",fileformat,sep=""), width = ww, height = wh, pointsize = pointsize, paper = paper), "pdf" = pdf(file = paste(filename,".",fileformat,sep=""), width = ww, height = wh, pointsize = pointsize, paper = paper)) plotsfkt() dev.off() } # switch between different file formats for additional plot saving (if saveit = TRUE) # if (saveit){ if (!is.null(addformat)){ switch(addformat,"jpeg" = jpeg(filename = paste(filename,".",addformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, quality = quality, bg = bg,res = pres), "png" = png(filename = paste(filename,".",addformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, bg = bg,res = pres), "bmp" = bmp(filename = paste(filename,".",addformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, bg = bg,res = pres), "tiff" = tiff(filename = paste(filename,".",addformat,sep=""), width = pwidth, height = pheight,units = units, pointsize = pointsize, bg = bg,res = pres), "ps" = postscript(file = paste(filename,".",addformat,sep=""), width = ww, height = wh, pointsize = pointsize, paper = paper), "pdf" = pdf(file = paste(filename,".",addformat,sep=""), width = ww, height = wh, pointsize = pointsize, paper = paper)) plotsfkt() dev.off() } } # should plotting be repressed in R (if notinR = TRUE) # if (!notinR){ dev.new(width = ww,height = wh,pointsize = dev.pointsize) plotsfkt() } } ### alias ### LSD.plotit = plotit LSD/R/LSD.heatscatter.R0000744000176200001440000004505413672347015014171 0ustar liggesusers ### heatscatterpoints ### #' @export #' @name heatscatterpoints #' @aliases LSD.heatscatterpoints #' @title A colored scatterplot based on a two-dimensional Kernel Density Estimation (add to an existing plot) #' @description Visualize two dimensional data in a three dimensional fashion facilitating a color encoded Kernel Density Estimation (add to an existing plot). #' @param x a numeric vector. #' @param y a numeric vector. #' @param pch plotting 'character'. This can either be a single character or an integer code for one of a set of graphics symbols. (see '?pch', to be passed to plot). #' @param cexplot a numerical value giving the amount by which the points should be magnified relative to the default. #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @param grid an integer specifying the size of the grid used for the KDE. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param only a character string which contains 'x' if the density should only be computed for the x axis, 'y' for the y axis (defaults to 'none' for the two-dimensional case). #' @param add.contour logical: if \code{TRUE} (\code{FALSE} by default), the contour lines are added to the plot. #' @param nlevels an integer giving the number of levels of the contour lines. #' @param color.contour R build-in color for the contour lines. #' @param greyscale logical: if \code{TRUE} (\code{FALSE} by default), the used colorpalette is converted to greyscales. #' @param log a character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic. #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @note Two-Dimensional Kernel Density Estimation adapted and modified from Venables and Ripley's MASS package (see reference). #' @references Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. #' @examples points = 10^4 #' x = c(rnorm(points/2),rnorm(points/2)+4) #' y = x + rnorm(points,sd=0.8) #' x = sign(x)*abs(x)^1.3 #' #' plot.new() #' plot.window(xlim = c(-5,15),ylim = c(-4,8)) #' heatscatterpoints(x,y,add.contour=TRUE,color.contour="green",greyscale=TRUE) #' axis(1) #' axis(2) #' box() #' @keywords scatterplot heatcolors heatscatterpoints = function(x,y,pch = 19,cexplot = 0.5,nrcol = 30,grid = 100,colpal = "heat",simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,rev = FALSE,xlim = NULL,ylim = NULL,only = "none",add.contour = FALSE,nlevels = 10,color.contour = "black",greyscale = FALSE,log = "",...) { # soundcheck # if (!is.vector(x) | !is.vector(y)) stop("First two argument must be numeric vectors!") if (length(x) != length(y)) stop("Data vectors must be of the same length!") sound = which((!(is.na(x)|is.nan(x)|(x==Inf)|(x==-Inf))) & (!(is.na(y)|is.nan(y)|(y==Inf)|(y==-Inf)))) if (length(sound)==0) stop("There are no valid point pairs to plot!") x = x[sound] y = y[sound] if (!is.null(xlim)){cut = x >= xlim[1] & x <= xlim[2] x = x[cut] y = y[cut] } if (!is.null(ylim)){cut = y >= ylim[1] & y <= ylim[2] y = y[cut] x = x[cut] } # color handling # colpal = colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev) if (greyscale){colpal = convertgrey(colpal)} # binninmg function # todiscrete = function(t,tmin,tmax,bins){ erg = round((t-tmin)/(tmax-tmin)*bins+0.5) erg = pmin(pmax(erg,1),bins) return(erg) } # kde2d.adj function: adapted and modified from Venables and Ripley's MASS package (distributed under the GPL-2 | GPL-3 license, https://cran.r-project.org/web/packages/MASS/index.html) # kde2d.adj = function(x,y,h,n = 25,lims = c(range(x),range(y)),only = "none"){ nx = length(x) gx = seq.int(lims[1],lims[2],length.out = n) gy = seq.int(lims[3],lims[4],length.out = n) bandwidth.nrd.adj = function(x) { r = quantile(x,c(0.25,0.75)) h = (r[2] - r[1])/1.34 return(4*1.06*min(sqrt(var(x)),h)*length(x)^(-1/5)) } if (missing(h)) { bx = bandwidth.nrd.adj(x) by = bandwidth.nrd.adj(y) if (all(c(bx,by) == 0)){h = rep(0.01,2)} else if (any(c(bx,by) == 0)){h = rep(max(bx,by),2)} else {h = c(bx,by)} } else h = rep(h,length.out = 2) h = h/4 ax = outer(gx,x,"-")/h[1] ay = outer(gy,y,"-")/h[2] norm.ax = dnorm(ax) norm.ay = dnorm(ay) if (only == "x"){norm.ay = rep(1,length(ay))} if (only == "y"){norm.ax = rep(1,length(ax))} z = tcrossprod(matrix(norm.ax,,nx),matrix(norm.ay,,nx))/(nx*h[1]*h[2]) list(x = gx,y = gy,z = z) } # handle 'log' option # if (log == ""){ xlog = x ylog = y } else if (log == "x"){ xlog = log(x,10) ylog = y } else if (log == "y"){ xlog = x ylog = log(y,10) } else if (log %in% c("xy","yx")){ xlog = log(x,10) ylog = log(y,10) } # estimate two-dimensional KDE for color encoding # d = kde2d.adj(xlog,ylog,n=grid,only=only) # binning # xdiscrete = todiscrete(xlog,min(xlog),max(xlog),bins=grid) ydiscrete = todiscrete(ylog,min(ylog),max(ylog),bins=grid) # color assignment # getfrommat = function(a){d$z[a[1],a[2]]} heatvec = unlist(apply(cbind(xdiscrete,ydiscrete),1,getfrommat)) coldiscrete = todiscrete(heatvec,min(d$z),max(d$z),bins=nrcol) # add to existing graphics device # points(x,y,col=colpal[coldiscrete],pch=pch,cex=cexplot,...) # handle 'add.contour' option # if (add.contour){contour(d,add=TRUE,nlevels=nlevels,col=color.contour)} } ### aliases ### LSD.heatscatterpoints = heatscatterpoints ### heatscatter ### #' @export #' @name heatscatter #' @aliases LSD.heatscatter #' @title A colored scatterplot based on a two-dimensional Kernel Density Estimation #' @description Visualize two dimensional data in a three dimensional fashion facilitating a color encoded Kernel Density Estimation. #' @param x a numeric vector. #' @param y a numeric vector. #' @param pch plotting 'character'. This can either be a single character or an integer code for one of a set of graphics symbols. (see '?pch', to be passed to plot). #' @param cexplot a numerical value giving the amount by which the points should be magnified relative to the default. #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @param grid an integer specifying the size of the grid used for the KDE. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param xlab x labels, standard graphics parameter. #' @param ylab y labels, standard graphics parameter. #' @param main title(s) of the plot, standard graphics parameter. #' @param cor logical: if \code{TRUE} (\code{FALSE} by default), the correlation is added to the title. #' @param method a character specifying the correlation method to use ('spearman' (default), 'pearson' or 'kendall'). #' @param only a character string which contains 'x' if the density should only be computed for the x axis, 'y' for the y axis (defaults to 'none' for the two-dimensional case). #' @param add.contour logical: if \code{TRUE} (\code{FALSE} by default), the contour lines are added to the plot. #' @param nlevels an integer giving the number of levels of the contour lines. #' @param color.contour R build-in color for the contour lines. #' @param greyscale logical: if \code{TRUE} (\code{FALSE} by default), the used colorpalette is converted to greyscales. #' @param log a character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic. #' @param ... additional parameters to be passed to points and plot. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @note Two-Dimensional Kernel Density Estimation adapted and modified from Venables and Ripley's MASS package (see reference). #' @references Venables, W. N. and Ripley, B. D. (2002) \emph{Modern Applied Statistics with S.} Fourth edition. Springer. #' @examples points = 10^4 #' x = c(rnorm(points/2),rnorm(points/2)+4) #' y = x + rnorm(points,sd=0.8) #' x = sign(x)*abs(x)^1.3 #' #' heatscatter(x,y) #' #' heatscatter(x,y,colpal="bl2gr2rd",main="bl2gr2rd",cor=FALSE) #' #' heatscatter(x,y,cor=FALSE,add.contour=TRUE,color.contour="red",greyscale=TRUE) #' #' heatscatter(x,y,colpal="spectral",cor=FALSE,add.contour=TRUE) #' @keywords scatterplot heatcolors heatscatter = function(x,y,pch = 19,cexplot = 0.5,nrcol = 30,grid = 100,colpal = "heat",simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,rev = FALSE,xlim = NULL,ylim = NULL,xlab = NULL,ylab = NULL,main = "heatscatter",cor = FALSE,method = "spearman",only = "none",add.contour = FALSE,nlevels = 10,color.contour = "black",greyscale = FALSE,log = "",...) { # parse variable names # if (is.null(xlab)){xlab = deparse(substitute(x))} if (is.null(ylab)){ylab = deparse(substitute(y))} # soundcheck # if (!is.vector(x) | !is.vector(y)) stop("First two argument must be numeric vectors!") if (length(x) != length(y)) stop("Data vectors must be of the same length!") sound = which((!(is.na(x)|is.nan(x)|(x==Inf)|(x==-Inf))) & (!(is.na(y)|is.nan(y)|(y==Inf)|(y==-Inf)))) if (length(sound)==0) stop("There are no valid point pairs to plot!") x = x[sound] y = y[sound] if (!is.null(xlim)){cut = x >= xlim[1] & x <= xlim[2] x = x[cut] y = y[cut] } if (!is.null(ylim)){cut = y >= ylim[1] & y <= ylim[2] y = y[cut] x = x[cut] } # handle 'log' option # if (log == ""){ valid = 1:length(x) } else if (log == "x"){ valid = which(x > 0) } else if (log == "y"){ valid = which(y > 0) } else if (log %in% c("xy","yx")){ valid = intersect(which(x > 0),which(y > 0)) } x = x[valid] y = y[valid] # handle 'cor' option # if (cor){main = paste(main," cor = ",round(cor(x,y,method=method),digits=2))} # handle graphics device # plot(x,y,xlim=xlim,ylim=ylim,xlab=xlab,ylab=ylab,main="",type = "n",log = log,...) heatscatterpoints(x,y,pch = pch,cexplot = cexplot,nrcol = nrcol,grid = grid,colpal = colpal,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev,xlim = xlim,ylim = ylim,only = only,add.contour = add.contour,nlevels = nlevels,color.contour = color.contour,greyscale = greyscale,log = log,...) mtext(paste(main),3,2,cex=1.25) } ### aliases ### LSD.heatscatter = heatscatter ### heatpairs ### #' @export #' @name heatpairs #' @aliases LSD.heatpairs #' @title Pairwise colored scatterplot based on a two-dimensional Kernel Density Estimation #' @description Pairwise visualization of two dimensional data in a three dimensional fashion facilitating a color encoded Kernel Density Estimation. #' @param mat a matrix with numerical entries. #' @param main title(s) of the plot, standard graphics parameter. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param labels a character vector giving the labels to be shown on the diagonal. #' @param add.points logical: if \code{TRUE} (\code{FALSE} by default), a certain 'group' of points can be colored in all pairwise plots. #' @param group indices or rownames of 'mat' to be highlighted in all pairwise plots (not necessarily all). #' @param color.group R build-in color in which the 'group' of points should be highlighted. #' @param method a character specifying the correlation method to use ('spearman' (default), 'pearson' or 'kendall'). #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param pch plotting 'character'. This can either be a single character or an integer code for one of a set of graphics symbols. (see '?pch', to be passed to plot). #' @param cexplot a numerical value giving the amount by which the points should be magnified relative to the default. #' @param cor.cex a numerical value giving the amount by which the correlation characters should be magnified relative to the default. #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @param grid an integer specifying the size of the grid used for the KDE. #' @param only a character string which contains 'x' if the density should only be computed for the x axis, 'y' for the y axis (defaults to 'none' for the two-dimensional case). #' @param add.contour logical: if \code{TRUE} (\code{FALSE} by default), the contour lines are added to the plot. #' @param nlevels an integer giving the number of levels of the contour lines. #' @param color.contour R build-in color for the contour lines. #' @param greyscale logical: if \code{TRUE} (\code{FALSE} by default), the used colorpalette is converted to greyscales. #' @param log a character string which contains "x" if the x axis is to be logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if both axes are to be logarithmic. #' @param ... additional parameters to be passed to points and plot #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples points = 10^4 #' x = rnorm(points/2) #' x = c(x,x+2.5) #' y = x + rnorm(points,sd=0.75) #' x = sign(x)*abs(x)^1.3 #' mat = cbind(x,y,x + rnorm(points,sd=0.5)) #' colnames(mat) = c("x","y","z") #' rownames(mat) = 1:nrow(mat) #' #' heatpairs(mat,labels=c(expression(Xi),expression(Lambda),expression(Delta))) #' @keywords scatterplot heatcolors heatpairs = function(mat,main = "heatpairs",xlim = NULL,ylim = NULL,labels = NULL,add.points = FALSE,group = NULL,color.group = "magenta",method = "spearman",colpal = "heat",simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,rev = FALSE,pch=19,cexplot=0.5,cor.cex = 2.5,nrcol=30,grid=100,only = "none",add.contour = FALSE,nlevels = 10,color.contour = "black",greyscale = FALSE,log = "",...) { if (!is.matrix(mat)) stop("First argument must be a matrix !") if (is.null(xlim)){xlim = c(min(mat,na.rm=TRUE),max(mat,na.rm=TRUE))} if (is.null(ylim)){ylim = c(min(mat,na.rm=TRUE),max(mat,na.rm=TRUE))} if(is.null(labels)){labels = colnames(mat)} # handle 'log' option # if (log == ""){ valid = 1:dim(mat)[1] } else if (log %in% c("x","y","xy","yx")){ valid = apply(mat,1,function(x){all(x > 0)}) } mat = mat[valid,] pairs(mat,labels=labels,xlim=xlim,ylim=ylim,lower.panel=function(x,y,...){{if (log == ""){x.pos = diff(xlim)/2 + xlim[1];y.pos = diff(ylim)/2 + ylim[1]} else if (log == "x"){x.pos = 10^(diff(log(xlim,10))/2 + log(xlim,10)[1]);y.pos = diff(ylim)/2 + ylim[1]} else if (log == "y"){x.pos = diff(xlim)/2 + xlim[1];y.pos = 10^(diff(log(ylim,10))/2 + log(ylim,10)[1])} else if (log %in% c("xy","yx")){x.pos = 10^(diff(log(xlim,10))/2 + log(xlim,10)[1]);y.pos = 10^(diff(log(ylim,10))/2 + log(ylim,10)[1])}};text(x.pos,y.pos,round(cor(x,y,method=method,use="na.or.complete"),digits=2),cex=cor.cex)},main=main,upper.panel=function(x,y,...){heatscatterpoints(x,y,colpal=colpal,pch=pch,cexplot=cexplot,nrcol=nrcol,grid=grid,simulate=simulate,daltonize=daltonize,cvd=cvd,alpha=alpha,rev=rev,only=only,add.contour=add.contour,nlevels=nlevels,color.contour=color.contour,greyscale=greyscale,log = log,...);if (log == ""){abline(a=0,b=1)} else if (log == "x"){lines(seq(xlim[1],xlim[2],length.out = 100),seq(ylim[1],ylim[2],length.out = 100))} else if (log == "y"){lines(seq(xlim[1],xlim[2],length.out = 100),seq(ylim[1],ylim[2],length.out = 100))} else if (log %in% c("xy","yx")){abline(a=0,b=1)};if (add.points){points(x[rownames(mat) %in% group],y[rownames(mat) %in% group],col=color.group,log = log,...)}},log = log,...) } ### aliases ### LSD.heatpairs = heatpairs LSD/R/LSD.heatboxplot.R0000755000176200001440000002314312452750072014204 0ustar liggesusers ### densitylane ### #' @name densitylane #' @aliases LSD.densitylane #' @title Visualize a density in a rectangular fashion #' @description Add a color stripe to an existing plot based on a kernel density estimate. #' @param x density$x values of a density object. #' @param y density$y values of a density object. #' @param pos the x co-ordinate of the lane (mid point). #' @param width a numeric value giving the width of the lane. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param horizontal logical: if \code{TRUE} (\code{FALSE} by default), rotation of 90 degrees is applied. #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @keywords density densitylane = function(x,y,pos = 1,width = 0.4,colpal = "standard",rev = FALSE,simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,horizontal = horizontal,nrcol = 75) { if (!is.vector(x) | !is.vector(y)) stop("First two argument must be vectors!") if (length(x) != length(y)) stop("Data vectors must be of the same length!") colpalette = rev(colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev)) ycol = pmin(pmax(round((y-min(y))/(max(y)-min(y))*nrcol+0.5),1),nrcol) if (horizontal){for (j in 1:(length(x)-1)){rect(x[j],pos-width/2,x[j+1],pos+width/2,col=colpalette[ycol[j]],border=NA)}} else {for (j in 1:(length(x)-1)){rect(pos-width/2,x[j],pos+width/2,x[j+1],col=colpalette[ycol[j]],border=NA)}} } ### aliases ### LSD.densitylane = densitylane ### heatboxplot ### #' @export #' @name heatboxplot #' @aliases LSD.heatboxplot #' @title Heatboxplot: a colored boxplot #' @description A boxplot with an additional color stripe based on a kernel density estimate. #' @param x data as vector, matrix, list or data.frame. #' @param horizontal logical: if \code{TRUE} (\code{FALSE} by default), rotation of 90 degrees is applied. #' @param add logical: if \code{TRUE} (\code{FALSE} by default), the boxplot is added to an existing plot. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param colpals a character vector containing names of \code{LSD} colorpalettes (see disco() or \code{\link{disco}}). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @param lwd linewidth of the box and whiskers. #' @param axes logical: if \code{TRUE} (by default), the axes are plotted. #' @param labels a character vector of labels. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param xlab x label, standard graphics parameter. #' @param ylab y label, standard graphics parameter. #' @param main title(s) of the plot, standard graphics parameter. #' @param nolab logical: if \code{TRUE} (\code{FALSE} by default), the title and ylab are suppressed. #' @param outline logical: if \code{TRUE} (by default), outliers are plotted. #' @param boxonly logical: if \code{TRUE} (\code{FALSE} by default), the density is only be plotted in the box. #' @param adjust a numeric value giving the scaling factor for the used bandwidth (defaults to 1). #' @param quant.from a numeric value (between 0 and 1) giving the quantile from which the density lane should be plotted. #' @param quant.to a numeric value (between 0 and 1) giving the quantile to which the density lane should be plotted. #' @param range a numeric value to determine how far the plot whiskers extend out from the box. #' @param border an R build-in color for the box and whiskers. #' @param plot.boxplot logical: if \code{TRUE} (by default), the boxplot is added to the density. #' @param add.quartiles if \code{TRUE} (\code{FALSE} by default), only the box of the boxplot is added (if \code{plot.boxplot = FALSE}). #' @param add.box logical: if \code{TRUE} (by default), the box is added to the plot. #' @param n.density an integer specifying the number of equally spaced points at which the density is to be estimated. #' @param cexbox a numerical value giving the amount by which the boxes should be magnified relative to the default. #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples f = c(rnorm(200),rnorm(200)+4) #' h = rf(500,15,15)*10 #' g = rnorm(300)+1 #' #' heatboxplot(h) #' #' heatboxplot(list(f=f,g=g),colpals=c("rdpu","greens"),labels=c("bimodal","unimodal")) #' @keywords boxplot heatboxplot = function(x,horizontal = FALSE,add = FALSE,colpal = "standard",rev = FALSE,simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,colpals = NULL,nrcol = 75,lwd = 1.75,axes = TRUE,labels = NULL,xlim = NULL,ylim = NULL,xlab = NULL,ylab = "",main = "heatboxplot",nolab = FALSE,outline = TRUE,boxonly = FALSE,adjust = 1,quant.from = 0.25,quant.to = 0.75,range = 1.5,border = "black",plot.boxplot = TRUE,add.quartiles = TRUE,add.box = FALSE,n.density = 1024,cexbox = 0.6,...) { if (!is.vector(x) & !is.matrix(x) & !is.list(x) & !is.data.frame(x)) stop("x must be a vector, matrix, list or a data.frame!") if (!is.list(x) & !is.matrix(x) & !is.data.frame(x)){x = cbind(x)} if (is.data.frame(x)){x = as.list(x)} if (is.matrix(x)){x = as.list(as.data.frame(x))} if (is.null(colpals)){colpals = rep(colpal,length(x))} if (!is.null(xlim)){print("xlim argument will be ignored!")} if (is.null(ylim)){ylim = range(unlist(x))} if (!is.null(xlab)){print("xlab argument will be ignored! Use labels instead!")} # necessary ? if (length(x) == 1){xlab = labels} if (length(x) == 1){cexbox = 0.4} if (length(x) > 1){boxwex = cexbox} else{boxwex = NULL} if (nolab){ylab = NULL} if (horizontal){labdummy = ylab ylab = xlab xlab = labdummy} limlist = list() qlimlist = list() for (i in 1:length(x)){limlist[[i]] = c(quantile(x[[i]],quant.from),quantile(x[[i]],quant.to))} for (i in 1:length(x)){qlimlist[[i]] = c(quantile(x[[i]],0.25),quantile(x[[i]],0.75))} boxplot(x,border="white",add=add,horizontal=horizontal,axes=axes,xlim=c(0.5,length(x)+0.5),ylim=ylim,width=NULL,boxwex=boxwex,main="",ylab=ylab,xlab=xlab,names=labels,outline=outline,range=range,lwd=lwd,...) if (!nolab){mtext(paste(main),3,2,cex=1.25)} for (j in 1:length(x)){xrel = x[[j]][x[[j]] >= ylim[1] & x[[j]] <= ylim[2]] dx = density(xrel,n=n.density,adjust=adjust) if(boxonly){dxx = dx$x[dx$x >= limlist[[j]][1] & dx$x <= limlist[[j]][2]] dxy = dx$y[dx$x >= limlist[[j]][1] & dx$x <= limlist[[j]][2]]} else {dxx = dx$x dxy = dx$y} densitylane(dxx,dxy,colpal=colpals[[j]],horizontal=horizontal,pos=j,width=cexbox,nrcol=nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha=alpha,rev = rev)} if (plot.boxplot){boxplot(x,add=TRUE,horizontal=horizontal,axes=axes,col="transparent",xlim=c(0.5,length(x)+0.5),ylim=ylim,width=NULL,boxwex=boxwex,names=labels,outline=outline,range=range,lwd=lwd,...)} if (!plot.boxplot){if (add.quartiles) {if (horizontal){ for (j in 1:length(x)){rect(qlimlist[[j]][1],j-cexbox/2,qlimlist[[j]][2],j+cexbox/2,border="grey40",lwd=lwd)} } else { for (j in 1:length(x)){rect(j-cexbox/2,qlimlist[[j]][1],j+cexbox/2,qlimlist[[j]][2],border="grey40",lwd=lwd)} }}} if (add.box){if (horizontal){ for (j in 1:length(x)){rect(limlist[[j]][1],j-cexbox/2,limlist[[j]][2],j+cexbox/2,border=border,lwd=lwd)} } else { for (j in 1:length(x)){rect(j-cexbox/2,limlist[[j]][1],j+cexbox/2,limlist[[j]][2],border=border,lwd=lwd)} }} } ### aliases ### LSD.heatboxplot = heatboxplot LSD/R/LSD.msdplot.r0000755000176200001440000001602013672346731013401 0ustar liggesusers ### singlemsdplot ### #' @export #' @name singlemsdplot #' @aliases LSD.singlemsdplot #' @title Visualize two-dimensional data clusters (add to an existing plot) #' @description Depict a numeric matrix or list utilizing the underlying mean and standard deviation estimates of one dimension in a color encoded fashion (add to an existing plot). #' @param input data as matrix or list. #' @param col a character vector of R build-in colors. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param bars logical: if \code{TRUE} (by default), error bars are added at each position. #' @param length a numeric value scaling the width of the bars. #' @param at a integer vector containing the x-positions corresponding to the columns of 'input'. #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples samples = 100 #' probes = 200 #' clus = matrix(rnorm(probes*samples,sd=1),ncol=probes) #' #' clus = rbind( #' t(t(clus)+sin(1:probes/10))+1:nrow(clus)/samples, #' t(t(clus)+sin(pi/2+1:probes/10))+1:nrow(clus)/samples) #' #' emptyplot(xlim = c(1,ncol(clus)),ylim = range(clus)) #' singlemsdplot(clus) #' axis(1) #' axis(2) #' box() #' @keywords mean sd singlemsdplot = function(input,col = "darkgreen",alpha = 50,bars = TRUE,length = 0.25,at = NULL) { if (!is.matrix(input) & !is.list(input)) stop("First argument must be a matrix or a list!") if (is.null(at)) if (is.matrix(input)){at=1:ncol(input)} else if (is.list(input)){at=1:length(input)} probes = length(at) if (is.matrix(input)){ means = apply(input,2,mean,na.rm=TRUE) sds = apply(input,2,sd,na.rm=TRUE) } else if (is.list(input)){ means = lapply(input,mean,na.rm=TRUE) means = sapply(means,c) sds = lapply(input,sd,na.rm=TRUE) sds = sapply(sds,c) } sds[is.na(sds)] = 0 qline = rbind(means+sds,means,means-sds) for (j in 1:2){polygon(at[c(1:probes,probes:1)],c(qline[j,],qline[j+1,probes:1]),col = convertcolor(col,alpha),lty=0)} lines(at,qline[2,],col=col,lwd=2) if (bars){options(warn = -1);arrows(at,means-sds,at,means+sds,angle=90,code=3,length=length,col=col);options(warn = 0)} } ### aliases ### LSD.singlemsdplot = singlemsdplot ### msdplot ### #' @export #' @name msdplot #' @aliases LSD.msdplot #' @title Visualize two-dimensional data clusters #' @description Depict a numeric matrix or list utilizing the underlying mean and standard deviation estimates of one dimension in a color encoded fashion. #' @param input matrix or list with numerical entries, quantiles of cols will define lines. #' @param label a character vector assigning rows/elements of 'input' to clusters (if specified, multiple clusters can be depicted in different colors and/or subsequent plots). #' @param at a integer vector containing the x-positions corresponding to the columns of 'input'. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param xlab x labels, standard graphics parameter. #' @param ylab y labels, standard graphics parameter. #' @param main title(s) of the plot, standard graphics parameter. #' @param xaxt a character which specifies the x axis type ("n" suppresses plotting of the axis). #' @param xlabels a character vector containing labels for the x-axis. #' @param las las=1: horizontal text, las=2: vertical text (x-axis labels). #' @param separate if \code{TRUE} (by default), different clusters are depicted in subsequent plots. #' @param size logical: if \code{TRUE} (by default), the size of each cluster is added to the title of the respective plot. #' @param col a character vector giving R build-in colors for different clusters. #' @param bars logical: if \code{TRUE} (by default), error bars are added at each position. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples at = c(2,4,8,16,32) #' clus = matrix(rnorm(500,sd=0.5),ncol=5) #' batch = sample(c(-8,-6,-4,-2),100,replace=TRUE) #' clus = clus + cbind(0,0.25*batch,0.5*batch,0.75*batch,batch) #' clus = clus - clus[,1] #' clus = t(t(clus)*c(0,0.1,0.25,0.5,1)) #' labs = paste("cluster",kmeans(clus,4)$cluster) #' #' colpal = c("darkgreen","darkblue","darkred","black") #' msdplot(clus,labs,at,separate=FALSE,col=colpal,alpha=25,xlabels=at) #' #' msdplot(clus,labs,at,col=colpal,alpha=50,xlabels=at) #' @keywords mean sd msdplot = function(input,label = NULL,at = NULL,xlim = NULL,ylim = NULL,xlab = "",ylab = "",main = "msdplot",xaxt = "s",xlabels = NULL,las = 1,separate = TRUE,size = TRUE,col = "darkgreen",bars = TRUE,alpha = 50,...) { if (!is.matrix(input) & !is.list(input)) stop("First argument must be a matrix or a list!") if (is.null(at)) if (is.matrix(input)){at=1:ncol(input)} else if (is.list(input)){at=1:length(input)} probes = length(at) if (is.null(xlim)) xlim=range(at) maxp = xlim[2] minp = xlim[1] if (is.null(ylim)) ylim=range(input,na.rm=TRUE) if (is.null(xlabels)) xlabels = 1:length(at) # one cluster in one plot if (is.null(label)){ plot(xlim,ylim,type="n",xaxt="n",xlab=xlab,ylab=ylab,main="",...) mtext(paste(main),3,2,cex=1.25) if (size){mtext(paste("( #",nrow(input)," )"),3,1,col="darkgrey",cex=0.75)} if (xaxt!="n") axis(side=1,las=las,at=at,labels=xlabels) singlemsdplot(input=input,at=at,alpha=alpha,col=col,bars=bars,length=0.02*range(at)) } # several clusters in one plot or several plots if (!is.null(label)){clusternames = unique(label) nrclusters = length(clusternames) if (!is.matrix(input)) stop("First argument must be a matrix for multiple clusters!") clustersets = split(1:nrow(input),factor(label)) if (separate==FALSE){ plot(xlim,ylim,type="n",xaxt="n",xlab=xlab,ylab=ylab,main="",...) mtext(paste(main),3,2,cex=1.25) if (size){mtext(paste("( #",nrow(input)," )"),3,1,col="darkgrey",cex=0.75)} if (xaxt!="n") axis(side=1,las=las,at=at,labels=xlabels)} if (separate==TRUE) par(mfrow=windowxy(nrclusters)) for (j in seq(clusternames)){ if (separate==TRUE){ if (length(main) == length(clustersets[[j]])) clustermain = main[j] else clustermain = paste(main,clusternames[j]) plot(xlim,ylim,type="n",xaxt="n",xlab=xlab,ylab=ylab,main="",...) mtext(paste(clustermain),3,2,cex=1.25) if (size){mtext(paste("( #",length(clustersets[[j]])," )"),3,1,col="darkgrey",cex=0.75)} if (xaxt!="n") axis(side=1,las=las,at=at,labels=xlabels) } singlemsdplot(input=input[clustersets[[j]],,drop=FALSE],at=at,alpha=alpha,col=col[j],bars=bars,length=0.02*range(at)) } } } ### aliases ### LSD.msdplot = msdplot LSD/R/LSD.makemovie.R0000755000176200001440000000372512453264171013635 0ustar liggesusers ### makemovie ### #' @export #' @name makemovie #' @aliases LSD.makemovie #' @title Interpolate rows of a matrix to extend the number of cols #' @description Interpolate rows of a matrix to yield a smooth transitions. #' @param input a matrix with numerical entries. #' @param timepoints a integer vector containing the timepoints corresponding to the columns of 'input'. #' @param timestep a non-negative integer specifying the number of timesteps between the existing timepoints (defaults to \code{1}, if not specified). #' @param motionline a integer vector giving the timepoints of the resulting matrix (derived from timepoints and timesteps by default). #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{clusterplot}}, \code{\link{align}}, \code{\link{demotour}} #' @examples len = 10 #' x = sin(seq(0,2*pi,length=len*2)) #' fun = function(){n=sample(1:len,1);return(x[n:(n+len-1)])} #' input = t(replicate(7,fun(),simplify=TRUE)) #' input = input + rnorm(length(input))/2 #' par(mfrow=c(1,2)) #' plotmatrix(input,main="original",cols=1:7,type="o") #' mov = makemovie(input,timestep=0.2) #' plotmatrix(mov,main="interpolated",cols=1:7,type="o") #' @keywords matrix makemovie = function(input,timepoints=NULL,timestep=1,motionline=NULL) { if (!is.matrix(input)) stop("'input' must be a matrix !") if (sum(is.na(input)) != 0) stop("'input' must not contain NAs !") if (is.null(timepoints)) timepoints = 1:ncol(input) sorted = order(timepoints,decreasing=FALSE) input = input[,sorted] timepoints = timepoints[sorted] colnames(input) = timepoints if (is.null(motionline)){ nrpics = ceiling(diff(range(timepoints))/timestep)+1 motionline = seq(timepoints[1],timepoints[length(timepoints)],length=nrpics) } timeline = function(x){splinefun(timepoints,x)(motionline)} movie = t(apply(input,1,timeline)) colnames(movie) = round(motionline,digits=2) return(movie) } ### aliases ### LSD.makemovie = makemovie LSD/R/LSD.fusionplot.R0000755000176200001440000002320112453447641014056 0ustar liggesusers ### singlefusionplot ### #' @export #' @name singlefusionplot #' @aliases LSD.singlefusionplot #' @title Visualize two-dimensional data clusters (add to an existing plot) #' @description Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion (add to an existing plot). #' @param x a numeric vector. #' @param y a numeric vector. #' @param fromto a numeric vector containing the range of quantiles (between 0 and 1) to be plotted. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified). #' @param outer.col R built-in color to be used for outlier lines (lines outside of 'fromto'). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param quartiles.col a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')). #' @param add.quartiles logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{fusionplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples x = 1:1000/300 #' y = rnorm(1000)+sin(2*x)*3 #' #' emptyplot(xlim = range(x),ylim = range(y)) #' singlefusionplot(x,y,colpal = "ylgnbu") #' axis(1) #' axis(2) #' box() #' @keywords cluster singlefusionplot = function(x,y,fromto = c(0.05,0.95),colpal = "standardheat",simulate = FALSE,daltonize = FALSE,cvd = "p",nrcol = 25,outer.col = "grey",rev = FALSE,alpha = NULL,quartiles.col = c("grey","black","grey"),add.quartiles = TRUE) { # kernel function # kernelf = function(y0,x0,x,y,width=0.1){ wx = 1/sqrt(2*pi)/width*exp(-(x0-x)^2/width^2/2) res = sum(wx[y<=y0]) / sum(wx) return(res) } # quantile function # quantf = function(x0,x,y,width=0.1,quantvector=seq(0,1,length=5)){ y0 = seq(min(y),max(y),length=100) quants = sapply(y0,kernelf,x0,x,y,width) hilf = approxfun(quants,y0,rule=2) return(hilf(quantvector)) } # calculate quantiles # xseq = seq(min(x),max(x),length=200) nrquants=2*nrcol quantvector = seq(fromto[1],fromto[2],length=nrquants) qline = sapply(xseq,quantf,x,y,width=0.1,quantvector=quantvector) # provide 'colpal' via colorpalette # colpal = colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev) colpal = c(rev(colpal),colpal) quantvec = seq(0,1,length=nrquants) for (j in 1:(nrquants - 1)){ polygon(c(xseq,rev(xseq)),c(qline[j,],rev(qline[j+1,])),col = colpal[j],lty = 0) } points(x,y,col = outer.col,pch = 19,cex = 0.3) # wrapper for the lines function # drawline = function(y,col="black",lwd=1,lty=1){lines(xseq,y,type="l",col=col,lwd=lwd,lty=lty)} # add lines corresponding to the quartiles # if (add.quartiles){ quantvector = seq(0.25,0.75,length=3) qline = sapply(xseq,quantf,x,y,width=0.1,quantvector=quantvector) drawline(qline[2,],col=quartiles.col[2],lwd=2) drawline(qline[1,],col=quartiles.col[1],lwd=2) drawline(qline[3,],col=quartiles.col[3],lwd=2) } } # alias # LSD.singlefusionplot = singlefusionplot ### fusionplot ### #' @export #' @name fusionplot #' @aliases LSD.fusionplot #' @title Visualize two-dimensional data clusters #' @description Depict a numeric matrix or list utilizing the underlying distribution quantiles of one dimension in a color encoded fashion. #' @param x a numeric vector. #' @param y a numeric vector. #' @param label a character vector assigning rows/elements of 'input' to clusters (if specified, multiple clusters can be depicted in different colors and/or subsequent plots). #' @param main title(s) of the plot, standard graphics parameter. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param fromto a numeric vector containing the range of quantiles (between 0 and 1) to be plotted. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 25, if not specified). #' @param outer.col R built-in color to be used for outlier lines (lines outside of 'fromto'). #' @param quartiles.col a character vector containing three R built-in colors for quartile lines (c('0.25','0.5','0.75')). #' @param add.quartiles logical: if \code{TRUE} (by default), lines are plotted corresponding to the quartiles. #' @param separate if \code{TRUE} (by default), different clusters are depicted in subsequent plots. #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param size logical: if \code{TRUE} (by default), the size of each cluster is added to the title of the respective plot. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param axes logical: if \code{TRUE} (by default), a box and axes are added to the plot (if \code{FALSE}, custom specification of axes can be achieved via basic R graphics functions). #' @param ... additional parameters to be passed to points and plot. #' @author Achim Tresch, Bjoern Schwalb #' @seealso \code{\link{singlefusionplot}}, \code{\link{align}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples nr = 750 #' x = 1:nr/300 #' y = c(rnorm(nr)+sin(2*x)*3,rnorm(nr)+sin(2*x+pi/2)*3) #' x = c(x,x) #' #' labs = paste("cluster",c(rep(c(1,2),each = nr))) #' colpals = c("oranges","pubu") #' qcol = c("transparent","black","transparent") #' fusionplot(x,y,labs,separate=FALSE,colpal=colpals,alpha=75,quartiles.col = qcol) #' @keywords cluster fusionplot = function(x,y,label = NULL,main = NULL,xlim = NULL,ylim = NULL,fromto = c(0.05,0.95),colpal = "standardheat",simulate = FALSE,daltonize = FALSE,cvd = "p",nrcol = 25,outer.col = "lightgrey",quartiles.col = c("grey","black","grey"),add.quartiles = TRUE,separate = TRUE,rev = FALSE,size = TRUE,alpha = NULL,axes = TRUE,...) { if (is.null(xlim)){xlim=c(min(x),max(x))} maxp = xlim[2] minp = xlim[1] if (is.null(ylim)){ylim=c(min(y),max(y))} # one cluster (i.e. one plot), if label = NULL # if (is.null(label)){ plot.new() plot.window(xlim = xlim,ylim = ylim,...) if (size){ main = paste(main," ( #",length(x)," )") } title(main) if (axes){ axis(1,...) axis(2) box() } singlefusionplot(x=x,y=y,fromto=fromto,colpal=colpal,simulate=simulate,daltonize=daltonize,cvd=cvd,nrcol=nrcol,outer.col=outer.col,add.quartiles=add.quartiles,quartiles.col=quartiles.col,rev=rev,alpha=alpha) } # multiple clusters, if label is specified # if (!is.null(label)) { clusternames = sort(unique(label)) nrclusters = length(clusternames) clustersets = split(1:length(x), factor(label)) if (!is.list(colpal)) colpal = as.list(colpal) if (length(colpal) < nrclusters) colpal = rep(colpal, nrclusters) # multiple clusters in one plots # if (separate == FALSE){ plot.new() plot.window(xlim = xlim,ylim = ylim,...) if (size){main = paste(main," ( #",length(x)," )")} title(main) if (axes){ axis(1,...) axis(2) box() } } # multiple clusters in subsequent plots # if (separate == TRUE) par(mfrow = windowxy(nrclusters)) for (j in seq(clusternames)){ if (separate == TRUE){ if (length(main) == length(clustersets[[j]])) clustermain = main[j] else clustermain = paste(main,clusternames[j]) plot.new() plot.window(xlim = xlim,ylim = ylim,...) if (size){clustermain = paste(clustermain," ( #",length(clustersets[[j]])," )")} title(clustermain) if (axes){ axis(1,...) axis(2) box() } } singlefusionplot(x=x[clustersets[[j]]],y=y[clustersets[[j]]],fromto=fromto,colpal=colpal[[j]],simulate=simulate,daltonize=daltonize,cvd=cvd,nrcol=nrcol,outer.col=outer.col,add.quartiles=add.quartiles,quartiles.col=quartiles.col,rev=rev,alpha=alpha) } } } # alias # LSD.fusionplot = fusionplot LSD/R/LSD.align.R0000755000176200001440000001104513672347201012744 0ustar liggesusers ### align ### #' @export #' @name align #' @aliases LSD.align #' @title Visualize two-dimensional data in a color encoded fashion #' @description Depict any matrix or list in a color encoded rectangular fashion. #' @param input matrix or list with any type of entries. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param label logical: if \code{TRUE} (\code{FALSE} by default), labels are added according to the color scheme (i.e. binning). #' @param digits integer indicating the number of decimals to be used for binning of continuous data. #' @param border color for rectangle border(s). Use border = NA to omit borders. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param main title of the plot, standard graphics parameter. #' @param axes logical: if \code{TRUE} (by default), a box and axes are added to the plot (if \code{FALSE}, custom specification of axes can be achieved via basic R graphics functions). #' @param ... additional parameters to be passed to points and plot. #' @author Phillipp Torkler, Bjoern Schwalb #' @seealso \code{\link{clusterplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples data(seqs) #' colpal = c("A" = "darkgreen","C" = "darkblue","G" = "yellow","T" = "darkred") #' align(seqs,colpal = colpal,label = TRUE,main = "DNA sequences") #' #' data(homer) #' colpal = c("white","black","yellow","wheat3") #' align(homer,colpal = colpal,main = "D'OH!",asp = 1,axes = FALSE) #' @keywords alignment sequence align = function(input,colpal = "heat",simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,label = FALSE,digits = 1,border = NULL,xlim = NULL,ylim = NULL,main = NULL,axes = TRUE,...) { # stops execution, if 'input' is neither a list nor a matrix and executes an error action # if (!is.matrix(input) & !is.list(input)) stop("'input' must be a matrix or a list !") # if 'input' is a list # if (is.list(input)){ # stops execution, if 'input'-list entries are of unequal length and executes an error action # if (any(sapply(input,length) != length(input[[1]]))){stop("'input'-list entries are of unequal length.")} # coerce to matrix # input = t(sapply(input,c)) } # bin the 'input' data via the round function # dim.input = dim(input) input = as.vector(input) options(warn = -1) input[!is.na(as.numeric(input))] = round(as.numeric(input[!is.na(as.numeric(input))]),digits = digits) options(warn = 0) dim(input) = dim.input # provide color encoding # colsize = length(unique(as.vector(input))) cat(colsize,"color encoding \n") if (length(colpal) > 1){if (colsize != length(colpal)){warning("'colpal' contains not enough colors to encode 'input' data!")}} names.colpal = NULL if (!is.null(names(colpal))){names.colpal = names(colpal)} colorset = colorpalette(colpal,colsize,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha) if (is.null(names.colpal)){names(colorset) = as.character(sort(unique(as.vector(input)),na.last = TRUE))} else {names(colorset) = names.colpal} # plot data in a grid like fashion # ysize = nrow(input) xsize = ncol(input) if (is.null(xlim)){xlim = c(0,xsize)} if (is.null(ylim)){ylim = c(0,ysize)} plot.new() plot.window(xlim = xlim,ylim = ylim,...) title(main) if (axes){ axis(1) axis(2) box() } dump = sapply(1:ysize,function(i){rect(1:xsize - 1,ysize - i,1:xsize,ysize - i + 1,col = colorset[as.character(input[i,1:xsize])],border = border);if (label){text(x = 1:xsize - 0.5,y = ysize - i + 1 - 0.5,label = input[i,1:xsize],col = complementarycolor(colorset[as.character(input[i,1:xsize])]))}}) } # alias # LSD.align = align LSD/R/LSD.pie.R0000755000176200001440000001226212453263621012430 0ustar liggesusers ### LSD.pie ### #' @export #' @name LSD.pie #' @title Custom-built piechart version #' @description Piecharts at arbitrary position and radii. #' @param props a numeric vector giving the relations of the pie pieces (need not to be normalized). #' @param x x-position of the piechart. #' @param y y-position of the piechart. #' @param radius a numeric value giving the radius of the piechart. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param edges an integer giving the number of edges the "circle" will have. #' @param add logical: if \code{TRUE} (\code{FALSE} by default), the pie is added to an existing plot. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param main title(s) of the plot, standard graphics parameter. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param addPercent logical: if \code{TRUE} (\code{FALSE} by default), the percentage of each slice is written inside of the pie. #' @param textcol a R build-in color for the percentages of \code{addPercent}. #' @param clockwise if \code{TRUE} (\code{FALSE} by default), slices drawn clockwise (counter clockwise, if \code{FALSE}). #' @param init.angle a numerical value representing an angle as a starting angle for the drawn slices. #' @param labels a character vector giving the names for the pie slices. #' @param cex scaling a numeric value giving the expansion factor for the slice names (if labels are given). #' @param cex.percentage a numeric value giving the expansion factor for the percentage values (if \code{addPercent = TRUE}). #' @param border a R build-in color giving the border color (NA by default). #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb, Carina Demel #' @seealso \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples emptyplot(xlim=c(1,9),ylim=c(1,9)) #' mtext(paste("LSD.pie: piecharts"),3,2,cex=1.25) #' polygon(c(4,2,4,7,8),c(4,8,4,2,8)) #' LSD.pie(sample(1:50,5),4,4,add=TRUE,radius=2,colpal="prgn",alpha=75) #' LSD.pie(sample(1:50,5),2,8,add=TRUE,colpal="prgn",alpha=75) #' LSD.pie(sample(1:50,5),8,8,add=TRUE,colpal="prgn",alpha=75) #' LSD.pie(sample(1:50,5),7,2,add=TRUE,colpal="prgn",alpha=75) #' @keywords pie LSD.pie = function(props,x = 0,y = 0,radius = 1,colpal = "prgn",simulate = FALSE,daltonize = FALSE,cvd = "p",edges = 1000,add = FALSE,xlim = c(-1,1),ylim = c(-1,1),main = "LSD.pie: piecharts",alpha = NULL,addPercent = FALSE,textcol = "black",clockwise = FALSE,init.angle=0,labels=c(),cex = 1,cex.percentage = cex,border=NA,...) { direction <- if (clockwise) -2 else 2 # circle coordinates # xx = sin(-(0:edges)/edges*direction*pi+init.angle*pi/180)*radius yy = cos(-(0:edges)/edges*direction*pi+init.angle*pi/180)*radius xxtext = sin(-(0:edges)/edges*direction*pi+init.angle*pi/180)*radius*0.7 yytext = cos(-(0:edges)/edges*direction*pi+init.angle*pi/180)*radius*0.7 xxlabels = sin(-(0:edges)/edges*direction*pi+init.angle*pi/180)*radius*1.25 yylabels = cos(-(0:edges)/edges*direction*pi+init.angle*pi/180)*radius*1.25 # number of pie pieces # n = length(props) # default colors # cols = colorpalette(colpal,n,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha) # pie segments # phi = cumsum(props)/sum(props)*edges phi = c(0,round(phi))+1 # plotting region # if (!add){ emptyplot(xlim=xlim,ylim=ylim,...) mtext(paste(main),3,2,cex=1.25) } # draw pie pieces # for (j in 1:n){xvec = c(x,x+xx[phi[j]:phi[j+1]]) yvec = c(y,y+yy[phi[j]:phi[j+1]]) polygon(xvec,yvec,col="white",border="black") polygon(xvec,yvec,col=cols[j],border="black") } for(j in 1:n){ if(addPercent){ xtext = c(x+xxtext[phi[j]:phi[j+1]]) ytext = c(y+yytext[phi[j]:phi[j+1]]) text(xtext[(length(xtext)+1)/2], ytext[(length(ytext)+1)/2], paste(round(props[j]/sum(props)*100,1), "%", sep=""), col=textcol, cex=cex.percentage) } if(length(labels)==n){ xlabel = c(x+xxlabels[phi[j]:phi[j+1]]) ylabel = c(y+yylabels[phi[j]:phi[j+1]]) lab = as.character(labels[j]) if (!is.na(lab) && nzchar(lab)) { Px = xlabel[(length(xlabel)+1)/2] Py = ylabel[(length(ylabel)+1)/2] text(Px,Py,labels[j],col=textcol,cex=cex,adj=ifelse(Px < 0,1,0),xpd=TRUE) } } } # return invisible # invisible() } LSD/R/LSD.utilities.R0000755000176200001440000000642213672352227013674 0ustar liggesusers ### emptyplot ### #' @export #' @name emptyplot #' @aliases LSD.emptyplot #' @title Wrapper function for an empty graphics device #' @description Calls an empty graphics device with a coordinate system of choice. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{demotour}} #' @examples emptyplot() #' @keywords empty plotting region emptyplot = function(xlim = c(-1,1),ylim = c(-1,1),...) { plot.new() plot.window(xlim = xlim,ylim = ylim,...) } ### alias ### LSD.emptyplot = emptyplot ### windowxy ### #' @export #' @name windowxy #' @aliases LSD.windowxy #' @title Factorization of the number of windows for plots with device partitions #' @description Create a factorization of the number of windows for plots with device partitions to be used in par(mfrow = ...). #' @param nrwin a non-negative integer specifying the number of windows. #' @author Bjoern Schwalb #' @seealso \code{\link{demotour}} #' @examples windowxy(20) #' @keywords factorization windowxy = function(nrwin = 1) { # factorize 'nrwin' # flsq = floor(sqrt(nrwin)) if (flsq^2==nrwin){ fac = c(flsq,flsq) } else if (nrwin <= flsq*(flsq+1)){ fac = c(flsq,flsq+1) } else { fac = c(flsq,flsq+2) } # return 'fac' # return(fac) } ### alias ### LSD.windowxy = windowxy ### webdesign ### #' @export #' @name webdesign #' @aliases LSD.webdesign #' @title Colored rectangular grid #' @description Adds a colored rectangular grid to an existing plot. #' @param xlim x limits, standard graphics parameter. #' @param ylim y limits, standard graphics parameter. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}). #' @param xlabels a character vector containing labels depicted parallel to the x-axis. #' @param ylabels a character vector containing labels depicted parallel to the y-axis. #' @param ... additional parameters to be passed to abline(). #' @author Bjoern Schwalb #' @seealso \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples emptyplot(c(-5,5),c(-5,5)) #' labels = c("2 fold","4 fold","8 fold") #' webdesign(c(-5,5),c(-5,5),lty = 2,xlabels = labels,ylabels = labels) #' @keywords grid web webdesign = function(xlim,ylim,colpal = "rdbu",xlabels = NULL,ylabels = NULL,...) { # provide color encoding # colpal = colorpalette(colpal,max(diff(xlim),diff(ylim))+1) # add abscissa and ordinate # abline(h=0,v=0,...) # line segments along the x-axis # xseq = xlim[2]:xlim[1] abline(h=xseq,col=colpal,...) # line segments along the y-axis # yseq = ylim[2]:ylim[1] abline(v=yseq,col=colpal,...) # add labels if !NULL # if (!is.null(xlabels)){text(1:length(ylabels),ylim[2]-1,xlabels,col=colpal[rev(which(yseq %in% 1:length(xlabels)))],adj=c(-0.1,-0.1))} if (!is.null(ylabels)){text(xlim[1]+1,-(1:length(ylabels)),ylabels,col=colpal[which(xseq %in% -(1:length(ylabels)))],adj=c(-0.1,-0.1))} } ### alias ### LSD.webdesign = webdesign LSD/R/LSD.intersphere.R0000755000176200001440000001205613672346757014224 0ustar liggesusers ### intersphere ### #' @export #' @name intersphere #' @aliases LSD.intersphere #' @title Intersphere: a fancy Venn diagram #' @description Create circles for visualizing overlaps between up to 4 datasets. #' @param data a list with n entries having elements that can be represented as sets (have union and intersect methods). #' @param colors a character vector of R build-in colors for circles representing different sets. #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param cex a numeric value giving the character expansion factor for intersect size text inside each circle. #' @param expand.circles a numeric value giving the expansion factor of circles (multiplicative). #' @param expand.lims a numeric value giving the expansion of x and y limits (additive). #' @param main title(s) of the plot, standard graphics parameter. #' @param onlySets vectors, which n-overlaps should be shown, default to all 1 < n < length(data). #' @author Sebastian Duemcke, Bjoern Schwalb #' @seealso \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples data = list( #' "A" = sample(1:200,100), #' "B" = sample(1:200,150), #' "C" = sample(1:200,50)) #' #' intersphere(data,colors = c("orange","skyblue","green")) #' #' data = list( #' "A" = sample(1:200,100), #' "B" = sample(1:200,150), #' "C" = sample(1:200,50), #' "D" = sample(1:200,75)) #' #' colors = c("orange","skyblue","green","purple") #' intersphere(data,colors,expand.circles = 0.5,expand.lims = 0.5) #' @keywords intersphere Venn intersphere = function(data,colors = NULL,alpha = 25,cex = 1,expand.circles = 1,expand.lims = 1.5,main = "intersphere: overlap diagram",onlySets = seq(length(data),2,by=-1)) { # number of cicles and overlap sizes # nb.circles = 2^length(data) - 1 get.n.overlap = function(n,data){combn(1:length(data),n,FUN=function(x,d){length(Reduce(intersect,d[x]))},simplify=TRUE,data)} get.overlap.size = function(d,...){length(Reduce(intersect,d[...]))} circle.sizes = unlist(lapply(1:length(data),get.n.overlap,data)) stopifnot(length(circle.sizes) == nb.circles) # scale of the radii # radius.scale = max(circle.sizes)/expand.circles radius.scale[radius.scale == 0] = 1 # default colors # if(is.null(colors)){colors = distinctcolors(nb.circles)} # get coordinates of points on unit circle (original sets) # xcoor = cos(seq(0, 2 * pi , length = length(data)+1)+pi/4)/0.5 ycoor = sin(seq(0, 2 * pi , length = length(data)+1)+pi/4)/0.5 coords = cbind(xcoor,ycoor) # define plotting region # xmax = max(xcoor) ymax = max(ycoor) plot(0,type="n",axes=FALSE,xlim=c(-xmax-expand.lims,xmax+expand.lims),ylim=c(-ymax-expand.lims,ymax+expand.lims),ylab="",xlab="",main="") mtext(paste(main),3,2,cex=1.25) # draw.circles function # draw.circles = function(x,y,radius,border = "black",col = "white"){ roots = seq(0,2*pi - 2*pi/100,by = 2*pi/100) for (circle in 1:length(radius)){ xv = cos(roots)*radius[circle] + x[circle] yv = sin(roots)*radius[circle] + y[circle] polygon(xv,yv,border = border,col = col[circle]) } } # draw function # draw = function(points,coords,data){ mass = apply(coords[points,],2,sum) / length(points) # shift mass point. new mass = third of way between center and pairwise intersect of neighbouring # if(length(points) == 2 && abs(points[1] - points[2]) == 2 && length(data) != 3){ mass = ((apply(coords[1:length(data),],2,sum) / length(data)) + (apply(coords[c(points[1],points[1]+1),],2,sum) / 2)) * 0.8 } # draw line segments to mass point in same color as origin # sapply(points,function(p){points(rbind(coords[p,],mass),col=colors[p],type="l")}) # draw mass points # draw.circles(mass[1],mass[2],r=sqrt(get.overlap.size(data,points)/(pi*radius.scale)),col="white",border="black") draw.circles(mass[1],mass[2],r=sqrt(get.overlap.size(data,points)/(pi*radius.scale)),col=convertcolor("grey50",alpha),border="grey50") # add text # text(mass[1],mass[2],labels=get.overlap.size(data,points),cex=cex) } # draw mass points, line segments and text # sapply(onlySets,function(n,draw,coords,data){combn(1:length(data),n,FUN=draw,simplify=FALSE,coords,data)},draw,coords,data) sapply(1:length(data),function(p){draw.circles(coords[p,1],coords[p,2],r=sqrt(length(data[[p]])/(pi*radius.scale)),col="white",border="black")}) sapply(1:length(data),function(p){draw.circles(coords[p,1],coords[p,2],r=sqrt(length(data[[p]])/(pi*radius.scale)),col=convertcolor(colors[p],alpha),border=colors[p])}) sapply(1:length(data),function(p){text(coords[p,1],coords[p,2],labels=length(data[[p]]),cex=cex)}) # return invisible # invisible() } ### aliases ### LSD.intersphere = intersphere LSD/R/LSD.heathist.r0000755000176200001440000000735412452755305013536 0ustar liggesusers ### heathist ### #' @export #' @name heathist #' @aliases LSD.heathist #' @title Color a histogram #' @description A histogram with an additional color stripe based on a kernel density estimate. #' @param x a numeric vector. #' @param breaks a numeric value giving the breaks of the histogram. #' @param xlab x label, standard graphics parameter. #' @param ylab y label, standard graphics parameter. #' @param main title(s) of the plot, standard graphics parameter. #' @param colpal a character vector containing R built-in color names or a name of a \code{LSD} colorpalette as a character string (see disco() or \code{\link{disco}}) (defaults to "heat", if not specified). #' @param rev logical: if \code{TRUE} (\code{FALSE} by default), a reversed colorpalette is used. #' @param simulate logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to simulate dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param daltonize logical: if \code{TRUE} (\code{FALSE} by default), a converted colorpalette is used to enhance dichromat vision according to \url{http://www.daltonize.org} (see \code{\link{daltonize}}). #' @param cvd character string implying the type of color vision deficiency ("p" for protanope, "d" for deuteranope or "t" for tritanope). #' @param alpha alpha value: a two-digit integer between 01 and 99 for color opacity, i.e. appearance of partial or full transparency (usage omitted by default). #' @param nobox logical: if \code{TRUE} (\code{FALSE} by default), the box of the plot is omitted. #' @param add.density if \code{TRUE} (\code{FALSE} by default), a density line is added to the histogram. #' @param col.density a R build-in color for the density line (if \code{add.density = TRUE}). #' @param add.rug if \code{TRUE} (\code{FALSE} by default), a rug (1-d plot of the data) is added below the histogram-bars. #' @param col.rug a R build-in color for the rug (if \code{add.rug = TRUE}). #' @param nrcol a non-negative integer specifying the number of colors to be used (defaults to 100, if not specified). #' @param ... additional parameters to be passed to points and plot. #' @author Bjoern Schwalb #' @seealso \code{\link{comparisonplot}}, \code{\link{demotour}}, \code{\link{disco}}, \code{\link{colorpalette}} #' @examples x = rnorm(1000,mean = sample(c(0,3),size = 1000,prob = c(0.4,0.6),replace = TRUE)) #' heathist(x,xlab="x",add.density=TRUE,col.rug="darkred") #' #' heathist(x,xlab="x",colpal = "matlablike") #' @keywords histogram heathist = function(x,breaks = 20,xlab = NULL,ylab = NULL,main = "heathist",colpal = "greys",rev = FALSE,simulate = FALSE,daltonize = FALSE,cvd = "p",alpha = NULL,nobox = FALSE,add.density = FALSE,col.density = "darkred",add.rug = TRUE,col.rug = "black",nrcol = 100,...) { if (!is.vector(x)) stop("x must be a vector!") if (is.null(xlab)){xlab = deparse(substitute(x))} if (!is.null(ylab)){print("ylab argument will be ignored!")} xhist = hist(x,plot = FALSE,breaks = breaks) d = density(x) plot(xhist,border = NA,freq = FALSE,xlab = xlab,main = "",...) mtext(paste(main),3,2,cex=1.25) usr = par("usr") dy = (max(xhist$density) - 0)/nrcol colpal = colorpalette(colpal,nrcol,simulate = simulate,daltonize = daltonize,cvd = cvd,alpha = alpha,rev = rev) for(i in 1:nrcol){ clip(usr[1],usr[2],0 + (i-1) * dy,0 + i*dy) plot(xhist,add = TRUE,axes = FALSE,col = colpal[i],border = NA,freq = FALSE,xlab = "",ylab = "",main = "") } do.call(clip,as.list(usr)) plot(xhist,add = TRUE,lwd = .5 ,freq = FALSE,axes = FALSE,xlab = "",ylab = "",main = "") if (add.density){lines(d,lwd = 4,col = col.density)} rug(x,col = col.rug) if (!nobox){box()} } ### aliases ### LSD.heathist = heathist LSD/MD50000644000176200001440000000561513672363532011225 0ustar liggesusers337734436c55d10686ffefa7f42b0a98 *DESCRIPTION fbb40a7541833da493c40e7cb795b362 *NAMESPACE beb068ad5944092c4d88727c44a2d309 *R/LSD.align.R 5507561af28265e1c104f6573a6e70c9 *R/LSD.clusterplot.R 51239ac63e3fe69e5132e470ed2aecb5 *R/LSD.color.r 00e81c7ffc1dbb64421631475850d67c *R/LSD.comparisonplot.r eef128ac64092b8e1f75113119fca544 *R/LSD.demotour.R e375dc9faaa71d0241167a8bb63ba5cd *R/LSD.ellipsescatter.R fed5367c4d697f13997fbf21c4c764d6 *R/LSD.fusionplot.R e650af00023c180adce10b8582ac11ff *R/LSD.heatboxplot.R 1499f054326b3042f691ca73d4f6d159 *R/LSD.heathist.r 000cedca173b037c72a717cb39f0371d *R/LSD.heatscatter.R 2604ed748061ef10692af05531368244 *R/LSD.intersphere.R 304e61ff7f24a5f9fc99f1205472b7fa *R/LSD.linesplot.r bffbc3be92833e552296026e24dcbb8f *R/LSD.makemovie.R 07a923757ae04159fd5050dfc7827d58 *R/LSD.msdplot.r 4268f32f202007b936a78596a138a1c9 *R/LSD.pie.R 4e4e9603631e17d238e81e08b1027bc0 *R/LSD.plotit.r 7772d2cd83ea35c7f88bd3b3ec5b81c4 *R/LSD.plotmatrix.r 20934f8cd97e275c8d32a3d0fd99c19b *R/LSD.utilities.R 6252e023977e67afbc45f7653cff37be *data/homer.RData a5a367d7fe36ffbaf5449388b300d460 *data/seqs.RData b8cafe1fd7942255cf60cfa10b03e0c7 *man/LSD.pie.Rd 148f4c758e703b1e8249ead7a43bd743 *man/align.Rd cecba49e890c1a1dcc49e540a27747a9 *man/clusterplot.Rd 1e253e6421b1ef644d64f6f0940b426d *man/colorpalette.Rd 2ad93a4bfaa4726608ad937a30f43d98 *man/comparisonplot.Rd 6e7080a1f97b8e8d50cc3c801933714e *man/complementarycolor.Rd c58e5f385693518ead554da79806a5e7 *man/convertcolor.Rd cf8cb9368a2bcd60da4d8de84eb1c11a *man/convertgrey.Rd b6919eb6c405e378e6d2c03455d3517b *man/daltonize.Rd c320b5f05ded66129e51476b64db82c1 *man/demotour.Rd b0415b39ef2bdad577db7abe275dbe75 *man/densitylane.Rd d9681296106b22b520effb1205ef0cfe *man/disco.Rd bc9fe97d7109f9a7a9a34cfb02d24bdc *man/distinctcolors.Rd ceba2ff97ac90596276cc1413e2dfaf9 *man/ellipsescatter.Rd 158329b876892979f6530f04106341e8 *man/emptyplot.Rd 972f3a1001af55f60740be9fc5e8aefb *man/fusionplot.Rd 05328167e9c185273f7a2b873beae801 *man/heatbarplot.Rd 576a305e0f3326ffb00f12b6aa0064c5 *man/heatboxplot.Rd 4fcf210f62b8bea6879d52f3c28c3698 *man/heathist.Rd 4198721d63a132da9b104958caca9451 *man/heatpairs.Rd 5d1c04fdf29758676f7840caf1238184 *man/heatscatter.Rd dc8ebff13650144b000441f4c4b3d95e *man/heatscatterpoints.Rd 9b28268f9c46dd85930e3daf8e8e0c6a *man/homer.Rd 329f92832d832cbff9a43a2b539aaf92 *man/intersphere.Rd eb926aabc4fd346db4699046aacc045b *man/linesplot.Rd 6be2a9c05a14a24e1df538b8a9f3771e *man/makemovie.Rd e411cf5974802202ffd378e6ba15feb4 *man/msdplot.Rd 58e6bf677b5f4fcc253d3a87165e7b2c *man/plotit.Rd d49e4e9e821444a98ef9c76e6ea86361 *man/plotmatrix.Rd b15a97797325e7ffebfe42ae437088ee *man/seqs.Rd c903e8bad2d65277e1e6964ad341ed87 *man/singleclusterplot.Rd da79c778cf2fecc540b11aa3aca1128d *man/singlefusionplot.Rd 0b43024e2826eba7cb7b78d53131437f *man/singlemsdplot.Rd cf20645a38919fd49051dc3a02514466 *man/webdesign.Rd 90ff491ddded85b91e3f2b08be2a8a18 *man/windowxy.Rd