Title: | Text Based Plots |
---|---|
Description: | Provides functions to produce rudimentary ascii graphics directly in the terminal window. Provides a basic plotting function (and equivalents of curve, density, acf and barplot) as well as boxplot and image functions. |
Authors: | Bjoern Bornkamp [aut, cre], Ivan Krylov [ctb] (txtimage) |
Maintainer: | Bjoern Bornkamp <[email protected]> |
License: | LGPL |
Version: | 1.0-4 |
Built: | 2024-11-09 02:50:50 UTC |
Source: | https://github.com/bbnkmp/txtplot |
Produces rudimentary ascii boxplots. The boxplot statistics are produced
using the boxplot.stats
function.
txtboxplot(..., range = 1.5, legend = NULL, xlab = NULL, width = round(options()$width * 0.8))
txtboxplot(..., range = 1.5, legend = NULL, xlab = NULL, width = round(options()$width * 0.8))
... |
Numeric vectors for which a boxplot should be produced |
range |
This determines how far the plot whiskers extend out from the
box. See |
legend |
Logical determining whether a legend should be drawn. If
|
xlab |
label for x-axis of boxplot, if NULL no x-label will be plotted |
width |
Width of the plot |
Due to rounding to a relatively crude grid results can only be approximate. E.g. the equally spaced axis ticks may be non-equally spaced in the plot.
Bjoern Bornkamp
rand1 <- rnorm(100, 1, 2) rand2 <- rnorm(50, 2, 2) rand3 <- rnorm(50, 2, 5) txtboxplot(rand1) txtboxplot(rand1, rand2, rand3)
rand1 <- rnorm(100, 1, 2) rand2 <- rnorm(50, 2, 2) rand3 <- rnorm(50, 2, 5) txtboxplot(rand1) txtboxplot(rand1, rand2, rand3)
Print a rudimentary image of a matrix on the R console using a user-supplied alphabet as a palette of sorts.
txtimage(z, width, height, yaxis = c('up', 'down'), transpose = TRUE, legend = TRUE, na.char = ' ', alphabet = 0:9, Lanczos = 3)
txtimage(z, width, height, yaxis = c('up', 'down'), transpose = TRUE, legend = TRUE, na.char = ' ', alphabet = 0:9, Lanczos = 3)
z |
Numeric matrix containing values to be plotted. |
width |
Desired width in characters. Defaults to full screen (by means of
|
height |
Desired height in characters. Defaults to |
yaxis |
Direction of the Y axis, |
transpose |
Whether to arrange rows by the X axis, like |
legend |
Whether to print the legend under the plot. If set, the returned
object will have the |
na.char |
Character to substitute for values satisfying |
alphabet |
Symbols to compose the plot of, linear scale. Either a single
multi-character string or a vector of single-character strings.
Defaults to |
Lanczos |
Positive integer defining the size of the Lanczos filter kernel.
Given a value of |
By default, txtimage
mimics the behaviour of image
,
drawing the rows of the matrix along the X axis and making the Y axis
grow from bottom to the top of the plot. The function can be made to
mimic matrix print
instead (rows arranged vertically from top to
bottom) by specifying yaxis
and image.transpose
arguments.
If requested width
or height
is different from dimensions
of the matrix, it is resampled using the Lanczos filter for a given
downsampling ratio and window parameter
:
When resampling, the rows and columns are assumed to correspond to a uniform linear grid.
The function is called for its side effect of printing the textual
plot on the R console using cat
, but it also invisibly returns
the resulting character matrix. If legend
is TRUE
, the
'cuts'
attribute contains the values separating the intervals
used for characters in the alphabet
(the copy of which is stored
in the 'alphabet'
attribute).
Resampling constant signals may produce rounding errors that get greatly
amplified after scaling them to diff(range(z))
. For constant
signals this is compensated by not allowing the resampling process to
increase the range of the signal, but if the range of the matrix values
is already really small (comparable to .Machine$double.eps
,
but not zero), the result of resampling process may not make sense.
Resampling high frequency signals (e.g.
outer(1:200, 1:200, function(x,y) cos(x*y))
) might give
hard-to-interpret results.
Ivan Krylov
Szeliski, R. (2010) Computer Vision: Algorithms and Applications. Section 3.5.2: Decimation.
symnum
, image
txtimage(datasets::volcano) ## Not run: ## try this if your terminal supports shade/block characters txtimage(datasets::volcano, alphabet = " \u2591\u2592\u2593\u2588") ## End(Not run)
txtimage(datasets::volcano) ## Not run: ## try this if your terminal supports shade/block characters txtimage(datasets::volcano, alphabet = " \u2591\u2592\u2593\u2588") ## End(Not run)
Provides a function to produce rudimentary ascii graphics directly in the terminal window.
txtplot
provides the basic plotting function of two numeric
vectors. All other functions below are based on this.txtcurve
is a text based equivalent of the curve
functiontxtdensity
is a text based density estimation function based on the
density
functiontxtacf
is a text based equivalent of the acf
function
and based on the acf
function.txtbarchart
is a text based barplot and plots the
relative frequences of the occurences of the different levels of a
factor (in percent)
txtplot(x, y = NULL, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL) txtcurve(expr, from = NULL, to = NULL, n = 101, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL) txtdensity(x, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL) txtacf(x, pch = "*", lag.max = 20, type = c("correlation", "covariance", "partial"), na.action = na.fail, demean = TRUE, width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL) txtbarchart(x, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), ylab = NULL)
txtplot(x, y = NULL, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL) txtcurve(expr, from = NULL, to = NULL, n = 101, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL) txtdensity(x, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL) txtacf(x, pch = "*", lag.max = 20, type = c("correlation", "covariance", "partial"), na.action = na.fail, demean = TRUE, width = round(options()$width*0.8), height = round(0.25*width), xlab = NULL, ylab = NULL) txtbarchart(x, pch = "*", width = round(options()$width*0.8), height = round(0.25*width), ylab = NULL)
x |
numeric containing the x-values to plot (for |
y |
numeric containing the x-values to plot (needs to be of the same
length as x). If NULL the numeric |
pch |
Plotting symbol |
width , height
|
Width and height of the plots in points |
xlab , ylab
|
labels for x and y axis |
xlim , ylim
|
limits for x and y axis in plot, if equal to NULL automatically determined from x and y. |
expr |
An expression to plot (containing x) |
from , to
|
Defines boundaries of plotting region for expr in txtcurve |
n |
integer specifying the number of x values between from and to |
lag.max , type , na.action , demean
|
arguments for call of |
Due to rounding to a relatively crude grid results can only be approximate! The equally spaced axis ticks, for example, may be non-equally spaced in the plot.
Due to the crude grid also there might be several points per pixel. The function uses the same plotting symbol no matter how many points coincide on one pixel
Bjoern Bornkamp
## basic plotting function require(stats) txtplot(cars[,1], cars[,2]) ## can include axis labels when desired txtplot(cars[,1], cars[,2], xlab = "speed", ylab = "distance") ## text based density plot txtdensity(rnorm(500)) ## text based plotting of functions txtcurve(x/(x+1), 0, 4, xlab = "Emax model") ## text based acf txtacf(rnorm(100)) ## text based barchart x <- factor(c("orange", "orange", "red", "green", "green", "red", "yellow", "purple", "purple", "orange")) txtbarchart(x) ## text based boxplots rand1 <- rnorm(100, 1, 2) rand2 <- rnorm(50, 2, 2) rand3 <- rnorm(50, 2, 5) txtboxplot(rand1) txtboxplot(rand1, rand2, rand3)
## basic plotting function require(stats) txtplot(cars[,1], cars[,2]) ## can include axis labels when desired txtplot(cars[,1], cars[,2], xlab = "speed", ylab = "distance") ## text based density plot txtdensity(rnorm(500)) ## text based plotting of functions txtcurve(x/(x+1), 0, 4, xlab = "Emax model") ## text based acf txtacf(rnorm(100)) ## text based barchart x <- factor(c("orange", "orange", "red", "green", "green", "red", "yellow", "purple", "purple", "orange")) txtbarchart(x) ## text based boxplots rand1 <- rnorm(100, 1, 2) rand2 <- rnorm(50, 2, 2) rand3 <- rnorm(50, 2, 5) txtboxplot(rand1) txtboxplot(rand1, rand2, rand3)