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

Description Usage Arguments Note Author(s) See Also Examples

View source: R/NostalgiR.R

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

1
2
3
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

1
2
3
4
5
6
7
8
9
## 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)

Example output

Loading required package: txtplot
      +----------+--------------+--------------+--------------++
      |                          ~~~~~~                        |
      |                         ~~    ~~                       |
  0.3 +                        ~~      ~~                      +
D     |                       ~~        ~~                     |
e     |                      ~~          ~~                    |
n 0.2 +               ~~~~~~~~            ~~                   +
s     |             ~~~                    ~~~                 |
i     |            ~~                        ~~                |
t     |           ~~                          ~~~              |
y 0.1 +          ~~                             ~~~            +
      |        ~~~                                ~~           |
      |      ~~~                                    ~~~        |
    0 +  ~~~~~       oo   o     o  oo  o  o    o      ~~~~~~~  +
      +----------+--------------+--------------+--------------++
                -2              0              2              4 
      ++----------+----------+-----------+----------+----------+
      |                      ~~~~                              |
  0.4 +                     ~~  ~~                             +
      |                    ~~    ~~                            |
D     |                    ~      ~                            |
e 0.3 +                   ~       ~                            +
n     |                  ~~        ~                           |
s     |                  ~         ~                           |
i 0.2 +                 ~~          ~                          +
t     |               ~~~           ~~                         |
y     |              ~~              ~                         |
  0.1 +            ~~~                ~~                       +
      |       ~~ ~~~                   ~~~~                    |
    0 +  ~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~  +
      ++----------+----------+-----------+----------+----------+
      -4         -2          0           2          4          6

NostalgiR documentation built on May 2, 2019, 2:45 p.m.