Learn R Programming

mdatools (version 0.7.0)

mdaplotg: Plotting function for several sets of objects

Description

mdaplotg is used to make scatter, line or bar plots or their combination for several sets of objects.

Usage

mdaplotg(data, type = "p", pch = 16, lty = 1, lwd = 1, bwd = 0.8, legend = NULL, xlab = NULL, ylab = NULL, main = NULL, labels = NULL, ylim = NULL, xlim = NULL, colmap = "default", legend.position = "topright", single.x = T, show.legend = T, show.labels = F, show.lines = F, show.grid = T, xticks = NULL, xticklabels = NULL, yticks = NULL, yticklabels = NULL, lab.col = "darkgray", lab.cex = 0.65, ...)

Arguments

data
a list with data values (see details below).
type
type of the plot ('p', 'l', 'b', 'h').
pch
a character for markers (same as plot parameter).
lty
the line type (same as plot parameter).
lwd
the line width (thickness) (same as plot parameter).
bwd
a width of a bar as a percent of a maximum space available for each bar.
legend
a vector with legend elements (if NULL, no legend will be shown).
xlab
a title for the x axis (same as plot parameter).
ylab
a title for the y axis (same as plot parameter).
main
an overall title for the plot (same as plot parameter).
labels
a matrix with text labels for data points (if NULL, row names for each group will be used).
ylim
limits for the y axis (if NULL, will be calculated automatically).
xlim
limits for the x axis (if NULL, will be calculated automatically).
colmap
a colormap to use for coloring the plot items.
legend.position
position of the legend ('topleft', 'topright', 'top', 'bottomleft', 'bottomright', 'bottom').
single.x
logical, is first column of data matrix used for x values (or every odd)?
show.legend
logical, show or not legend for the data objects.
show.labels
logical, show or not labels for the data objects.
show.lines
vector with two coordinates (x, y) to show horizontal and vertical line cross the point.
show.grid
logical, show or not a grid for the plot.
xticks
tick values for x axis.
xticklabels
labels for x ticks.
yticks
tick values for y axis.
yticklabels
labels for y ticks.
lab.col
color for data point labels.
lab.cex
size for data point labels.
...
other plotting arguments.

Details

The mdaplotg function is used to make a plot with several sets of objects. Simply speaking, use it when you need a plot with legend. For example to show line plot with spectra from calibration and test set, scatter plot for height and weight values for women and men, and so on.

Most of the parameters are similar to mdaplot, the difference is described below.

The data should be organized as a list, every item is a matrix with data for one set of objects. See examples for details.

There is no color grouping option, because color is used to separate the sets. Marker symbol, line style and type, etc. can be defined as a single value (one for all sets) and as a vector with one value for each set.

Examples

Run this code
### Examples of using mdaplotg

## 1. Show scatter plot for with height and weight values
## for males and females

data(people)

sex = people[, 'Sex']
fdata = cbind(people[sex == 1, 'Height'], people[sex == 1, 'Weight'])
mdata = cbind(people[sex == -1, 'Height'], people[sex == -1, 'Weight'])
colnames(fdata) = colnames(mdata) = c('Height', 'Weight')
pdata = list(fdata, mdata)

par(mfrow = c(2, 2))
mdaplotg(pdata, legend = c('female', 'male'))
mdaplotg(pdata, legend = c('female', 'male'), pch = c(17, 19), colmap = c('green', 'orange'))
mdaplotg(pdata, legend = c('female', 'male'), legend.position = 'topleft', colmap = 'gray')
mdaplotg(pdata, legend = c('female', 'male'), legend.position = 'topleft', show.labels = TRUE)
par(mfrow = c(1, 1))

## 2. Change tick values for x axis
mdaplotg(pdata, legend = c('female', 'male'), xticks = c(160, 175, 190),
         xticklabels = c('Short', 'Medium', 'Tall'))

## 3. Show line plots with spectra from calibration and test set of the Simdata

data(simdata)

cdata = cbind(simdata$wavelength, t(simdata$spectra.c))
tdata = cbind(simdata$wavelength, t(simdata$spectra.t))
pdata = list(cdata, tdata)

par(mfrow = c(2, 2))
mdaplotg(pdata, type = 'l', legend = c('cal', 'test'))
mdaplotg(pdata, type = 'l', legend = c('cal', 'test'), xlab = 'Wavelength, nm', ylab = 'Log(1/R)')
mdaplotg(pdata, type = 'l', legend = c('cal', 'test'), lty = c(3, 2))
mdaplotg(pdata, type = 'l', legend = c('cal', 'test'), lwd = 2, colmap = c('green', 'orange'))
par(mfrow = c(1, 1))

Run the code above in your browser using DataLab