Learn R Programming

IDPmisc (version 0.9.3)

Image: Display the Density of Points in a Scatter Plot by Colors

Description

The density of points in a scatter plot is encoded by color.

Usage

Image(x, y = NULL, pixs = 1, zmax = NULL, ztransf = function(x){x},
      colramp = IDPcolorRamp, factors = c(FALSE, FALSE))

Arguments

x, y
Coordinates of points whose density is plotted. If x is a matrix or a data.frame, the first two column are used as x and y respectively. y must be in this case NULL. x and y may be numer
pixs
Size of pixel in x- and y-direction in [mm] on the plotting device. When x and y are numeric, pixels are square. When x and y are factors or should be handled as factors (see argument
zmax
Maximum number of counts per pixel in the plot. When NULL, the density in the scatter plot is encoded from 0 to maximum number of counts per pixel observed. zmax must be equal or larger than maximum number of co
ztransf
Function to transform the number of counts per pixel, which will be mapped by the function in colramp to well defined colors. The user has to make sure that the transformed density lies in the range [0,zmax], where zmax
colramp
Color ramp to encode the number of the counts within a pixel by color.
factors
Vector of logicals indicating whether x and / or y should be handled as factors independently of their class.

Value

  • Maximum number of counts per pixel found. If the number is not an integer, it is rounded to the nearest integer which is greater.

Details

Before calling Image a plot must have been created by, e.g., calling plot(x,y,type="n"). This function ensures by default that the pixel has the same size in x- and y-direction. As a drawback, pixels may be unequally spaced, when there are only very few distinct (integer) values in x- or y-direction. When this is the case, the corresponding dimension should be declared as factor. (cf. argument factors). \crAsimilar solution for plotting densities is realized in the package fields: image.count. The main differences between the solution in IDPmisc and fields are the following: In Image the pixel size is defined in mm on the plotting device whereas in image.count the number of pixels in x- and y-direction are defined. Image works on ordinary plots whereas image.count needs the special plotting function image.plot. In addition, Image also works with factors as x- and / or y-coordinates. \crThisfunction is based on graphics

See Also

ipairs, ilagplot, ixyplot, image, image.count

Examples

Run this code
x <- rnorm(10000)
y <- rnorm(10000,10)
plot(x+y,y,type="n")
Image(x+y,y)
abline(a=0,b=1)

##
plot.default(iris$Species,iris$Petal.Width,
             xlim=c(0.5,3.5),
             type="n",axes=FALSE)
axis(1,at=1:3,lab=levels(iris$Species))
axis(2)
Image(iris$Species,iris$Petal.Width,pixs=3)

## The above can be merged to
ixyplot(iris$Species,iris$Petal.Width,pixs=3, minL.lab=10)

Run the code above in your browser using DataLab