Package 'NostalgiR'

Title: Advanced Text-Based Plots
Description: Provides functions to produce advanced ascii graphics, directly to the terminal window. This package utilizes the txtplot() function from the 'txtplot' package, to produce text-based histograms, empirical cumulative distribution function plots, scatterplots with fitted and regression lines, quantile plots, density plots, image plots, and contour plots.
Authors: Hien D. Nguyen
Maintainer: Hien D. Nguyen <[email protected]>
License: LGPL-3
Version: 1.0.2
Built: 2024-12-11 06:43:55 UTC
Source: CRAN

Help Index


nos.image text-based contour plot.

Description

Produces a text-based contour plot for the visualization of three-dimensional data that are stored in a matrix.

Usage

nos.contour(data, xmin = 1, xmax = dim(data)[1], ymin = 1,
  ymax = dim(data)[2], xlab = NULL, ylab = NULL, ratio = 0.35,
  width = round(options()$width * 0.8), height = round(ratio * width),
  pch = 1:5)

Arguments

data

A numeric matrix of data to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

xmin

A numeric value indicating the smallest x-axis value, which corresponds to the first row of data.

xmax

A numeric value indicating the greatest x-axis value, which corresponds to the last row of data.

ymin

A numeric value indicating the smallest y-axis value, which corresponds to the first column of data.

ymax

A numeric value indicating the greatest y-axis value, which corresponds to the last column of data.

xlab

Label of the x-axis of the plot.

ylab

Label of the y-axis of the plot.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A vector of single-character symbols. The length of the vector determines the number of contours to be plotted. From left to right, the symbols represent an increasing order of contour values.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position. The contour values are equally spaced quantiles between the 5% and 95% level, and are produced using the quantile function. The legend reports the value associated with each contour.

Author(s)

Hien D. Nguyen

See Also

quantile, contour, contourLines, volcano, and txtplot.

Examples

## Produce the contour plot of the volcano dataset, using the default plotting symbols.
library(datasets)
nos.contour(volcano)

## Produce the contour plot of the volcano dataset, using the plotting symbols letters[1:3].
library(datasets)
nos.contour(volcano,pch=letters[1:3])

nos.density text-based plot of a kernel density function.

Description

Plots a text-based of a kernel density function, with the option of plotting the location of the data points along the x-axis.

Usage

nos.density(data, xlab = NULL, ratio = 0.25, bw = "nrd0",
  kernel = "gaussian", locations = T, width = round(options()$width *
  0.8), height = round(ratio * width), pch = c("o", "~"))

Arguments

data

A numeric vector containing the values to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

xlab

Label of the x-axis of the plot.

ratio

Coefficient that controls the aspect ratio of the plot.

bw

A numerical value or character string to specify the bandwidth used for kernel density estimation. The default setting is 'nrd0', which is the default option in density; see density for other options.

kernel

A character string to specify the type of smoothing kernel used. The default setting is 'gaussian', which is the default option in density; see density for other options.

locations

If TRUE, the location of the data points are plotted along the x-axis. If FALSE, then the locations of the data points are not plotted.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A two dimensional vector of single-character symbols. The first symbol is for data point, and the second symbol is for the density curve.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position.

Author(s)

Hien D. Nguyen

See Also

density, plot, txtplot, and txtdensity.

Examples

## Plot a kernel density function of 10 random standard normal points with
## a Gaussian kernel and with the locations of the data plotted along the x-axis.
data <- rnorm(10)
nos.density(data)

## Plot a kernel density function of 100 random stanard normal points with
## a triangular kernel and without the locations of the data plotted along the x-axis.
data <- rnorm(100)
nos.density(data,kernel='triangular',location=FALSE)

nos.ecdf text-based plot of an empirical CDF.

Description

Plots a text-based empirical cumulative distribution function.

Usage

nos.ecdf(data, xlab = NULL, ratio = 0.25, width = round(options()$width *
  0.8), height = round(ratio * width), pch = "o")

Arguments

data

A numeric vector containing the values to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

xlab

Label of the x-axis of the plot.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A single-character plot symbol.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position.

Author(s)

Hien D. Nguyen

See Also

ecdf, plot and txtplot.

Examples

## Plot the empirical CDF of 10 random standard normal points with 'o' shaped points.
data <- rnorm(10)
nos.ecdf(data)

## Plot the empirical CDF of 100 random stanard normal points with '*' shaped points
data <- rnorm(100)
nos.ecdf(data,pch='*')

nos.hist text-based plot of a histogram.

Description

Plots a text-based of a histogram, with the option to plot densities or frequencies.

Usage

nos.hist(data, breaks = "Sturges", freq = T, xlab = NULL, ratio = 0.25,
  width = round(options()$width * 0.8), height = round(ratio * width),
  pch = "o")

Arguments

data

A numeric vector containing the values to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

breaks

Either a numerical value or a character string to specify the number of breaks to used. The default setting is 'Sturges', which is the default option in hist; see hist for other options.

freq

If TRUE, the y-coordinate will display frequencies. If FALSE, then the y-coordinate will display densities.

xlab

Label of the x-axis of the plot.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A single-character plot symbol.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position. Histogram columns are plotted at the midpoint of each bin.

Author(s)

Hien D. Nguyen

See Also

hist, and txtplot.

Examples

## Plot a histogram for the frequencies of 100 random standard normal points
## using 'Sturges' breaks and plot symbol 'o'.
data <- rnorm(100)
nos.hist(data)

## Plot a histogram for the densities of 1000 random chi-squared(3) points
## using 'FD' breaks and plot symbol '#'.
data <- rchisq(1000,3)
nos.hist(data,breaks='FD',freq=FALSE,pch='#')

nos.image text-based image plot.

Description

Produces a text-based image plot for the visualization of three-dimensional data that are stored in a matrix.

Usage

nos.image(data, xmin = 1, xmax = dim(data)[1], ymin = 1,
  ymax = dim(data)[2], xlab = NULL, ylab = NULL, ratio = 0.35,
  width = round(options()$width * 0.8), height = round(ratio * width),
  pch = c(".", "o", "x", "X", "#"))

Arguments

data

A numeric matrix of data to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

xmin

A numeric value indicating the smallest x-axis value, which corresponds to the first row of data.

xmax

A numeric value indicating the greatest x-axis value, which corresponds to the last row of data.

ymin

A numeric value indicating the smallest y-axis value, which corresponds to the first column of data.

ymax

A numeric value indicating the greatest y-axis value, which corresponds to the last column of data.

xlab

Label of the x-axis of the plot.

ylab

Label of the y-axis of the plot.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A vector of single-character symbols. The length of the vector determines the number of bins that the data is partitioned into. From left to right, the symbols represent an increasing order of binned.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position. The bins are equally spaced between the minimum and the maximum value of the data matrix, and are produced using the hist function. The legend reports the smallest and largest value of each bin associated with each plot symbol.

Author(s)

Hien D. Nguyen

See Also

hist, image, volcano, and txtplot.

Examples

## Produce the image plot of the volcano dataset, using the default plotting symbols.
library(datasets)
nos.image(volcano)

## Produce the image plot of the volcano dataset, using the plotting symbols 1:9.
library(datasets)
nos.image(volcano,pch=1:9)

nos.legend Generates a text-based legend for plots.

Description

Generates a text-based legend that relates plot characters to functional values or outcomes.

Usage

nos.legend(nams, legend = 1:length(nams), width)

Arguments

nams

A vector that specifies what each plot symbol represents.

legend

A character vector of the plot symbols.

width

A numeric value that specifies the number of characters to be printed before a line-break.

Author(s)

Hien D. Nguyen

See Also

txtplot.

Examples

## Generates a legend that relates the plot symbols c('a','b','c') to
## the functional values c(1,2,3) with line-breaks every 14 characters.
nos.legend(c(1,2,3),c('a','b','c'),14)

nos.qqnorm text-based normal quantile-quantile plots

Description

Produces a text-based normal quantile-quantile plot where the theoretical quantiles are plotted along the x-axis and the sample quantiles are plotted along the y-axis.

Usage

nos.qqnorm(data, line = T, ratio = 0.25, width = round(options()$width *
  0.8), height = round(ratio * width), pch = c("o", "~"))

Arguments

data

A numeric vector containing the values to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

line

If TRUE, the line of theoretical quantile equality is plotted. If FALSE, then the line of theoretical quantile equality is not plotted.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A two dimensional vector of single-character symbols. The first symbol is for data point, and the second symbol is for the line of theoretical quantile equality.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position.

Author(s)

Hien D. Nguyen

See Also

qqnorm, qqline and txtplot.

Examples

## Produce a normal quantile-quantile plot of 10 random standard normal points,
## without the line of theoretical quantile equality.
data <- rnorm(10)
nos.qqnorm(data,line=FALSE)

## Produce a normal quantile-quantile plot of 100 random chi-squared(3) points,
## with the line of theoretical quantile equality.
data <- rchisq(100,3)
nos.qqnorm(data)

nos.qqplot text-based generic quantile-quantile plots

Description

Produces a text-based quantile-quantile plot between two equal size samples, with the option of plotting a line of theoretical quantile equality.

Usage

nos.qqplot(x, y, xlab = NULL, ylab = NULL, line = T, ratio = 0.25,
  width = round(options()$width * 0.8), height = round(ratio * width),
  pch = c("o", "~"))

Arguments

x

A numeric vector containing the values to be plotted along the x-axis. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

y

A numeric vector containing the values to be plotted along the y-axis. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

xlab

Label of the x-axis of the plot.

ylab

Label of the y-axis of the plot.

line

If TRUE, the line of theoretical quantile equality is plotted. If FALSE, then the line of theoretical quantile equality is not plotted.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A two dimensional vector of single-character symbols. The first symbol is for data point, and the second symbol is for the line of theoretical quantile equality.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position.

Author(s)

Hien D. Nguyen

See Also

qqplot, qqline, ppoints, and txtplot.

Examples

## Produce a quantile-quantile plot between two samples of 10 random standard normal points,
## without the line of theoretical quantile equality.
x <- rnorm(10)
y <- rnorm(10)
nos.qqplot(x,y,line=FALSE)

## Produce a quantile-quantile plot of 100 random chi-squared(3) points against the
## true theoretical distribution, with the line of theoretical quantile equality.
y <- rchisq(100,3)
x <- qchisq(ppoints(100),3)
nos.qqplot(x,y,xlab='Theoretical Qs',ylab='Sample Qs')

nos.xyplot text-based scatter plot.

Description

Plots a text-based scatter plot, with the option of having a regression line, or a linear interpolation of the points.

Usage

nos.xyplot(x = 1:length(y), y, xlab = NULL, ylab = NULL, ratio = 0.25,
  width = round(options()$width * 0.8), height = round(ratio * width),
  pch = c("o", "~"), type = "p")

Arguments

x

A numeric vector containing the x-values to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

y

A numeric vector containing the y-values to be plotted. NA and NaN are allowed, but are removed for the plot. Infinities will cause an error.

xlab

Label of the x-axis of the plot.

ylab

Label of the y-axis of the plot.

ratio

Coefficient that controls the aspect ratio of the plot.

width

Width of the plot in points.

height

Height of the plot in points.

pch

A two dimensional vector of single-character symbols. The first symbol is for the x and y coordinate points, and the second symbol is for the interpolation or regression line.

type

One of the values in the set c('l','p','r','lp','pr'). Type 'l' plots a linear interpolation, type 'p' plots the x and y coordinates as points, type 'r' plots a linear regression line, type 'lp' plots x and y coordinates along with a linear interpolation, and type 'pr' plots x and y coordinates along with a linear regression line.

Note

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. Further, due to the crude grid also there might be several points per character. The function uses the same plotting symbol no matter how many points coincide on one character position.

Author(s)

Hien D. Nguyen

See Also

plot and txtplot.

Examples

## Plot 10 correlated points
x <- 10*runif(10)
y <- x + rnorm(10)
nos.xyplot(x,y,type='p',xlab='x',ylab='y')

## Plot 10 correlated points with a regression line
x <- 10*runif(10)
y <- x + rnorm(10)
nos.xyplot(x,y,type='pr',xlab='x',ylab='y')

## Plot 10 correlated points with a linear interpolation
x <- 10*runif(10)
y <- x + rnorm(10)
nos.xyplot(x,y,type='lp',xlab='x',ylab='y')