Mplot: Functions for plotting matrices, or for splitting them and...

Description Usage Arguments Value Author(s) Examples

Description

Mplot plots data from (a list of) matrices.

Msplit splits a matrix in a list according to factors (or unique values).

Mcommon creates a list of matrices that have only common variables.

Msummary and Mdescribe create suitable summaries of all columns of a matrix or list.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
  Mplot (M, ..., x = 1, select = NULL, which = select, 
         subset = NULL, ask = NULL, 
         legend = list(x = "center"), pos.legend = NULL,
         xyswap = FALSE, rev = "") 

  Msummary (M, ..., 
         select = NULL, which = select, 
         subset = NULL) 

  Mdescribe (M, ..., 
         select = NULL, which = select, 
         subset = NULL) 

  Msplit (M, split = 1, subset = NULL) 

  Mcommon (M, ..., verbose = FALSE)      

Arguments

M

Matrix or data.frame to be plotted, or treated. For Mplot, M can be a list with matrices or data.frames.

x

Name or number of the column to be used as the x-values.

select

Which variable/columns to be selected. This is added for consistency with the R-function subset.

which

The name(s) or the index to the variables that should be plotted or selected. Default = all variables, except time.

subset

Logical expression indicating elements or rows to keep in select: missing values are taken as FALSE

ask

Logical; if TRUE, the user is asked before each plot, if NULL the user is only asked if more than one page of plots is necessary and the current graphics device is set interactive, see par(ask) and dev.interactive.

legend

A list with parameters for the legend to be added. If FALSE, then no legend will be drawn.

pos.legend

The position of the legend, a number. The default is to put the legend in the last figure. Also allowed is pos.legend = 0, which will create a new figure with only the legend.

xyswap

If TRUE, then the x- and y-values will be swapped.

rev

a character string which contains "x" if the x axis is to be reversed, "y" if the y axis is to be reversed and "xy" or "yx" if both axes are to be reversed.

split

The name or number of the column with the factor according to which the matrix will be split.

verbose

If TRUE will write output to the screen.

...

Additional arguments passed to the methods. For Mplot: can also be extra matrices to plot. The arguments after ... must be matched exactly.

Value

Function Msplit returns a list with the matrices, split according to the factors; the names of the elements is set by the factor's name. It is similar to the R-function split.

Function Mcommon returns a list with the matrices, which only have the common variables.

Function Msummary returns a data.frame with summary values (minimum, first quantile, median, mean, 3rd quantile, maximum) for each column of the input (variable). If there are more than one object to be summarised, or if M is a list of objects, the name of the object is in the second column.

Function Mdescribe returns a data.frame with summary values (number of data, number of missing values, number of unique values, mean value, the standard deviation, the minimum, the p = 0.05, 0.1, 0.5, 0.9, 0.95 quantiles, and the maximum) for each column of the input (variable). If there are more than one object to be summarised, or if M is a list of objects, the name of the object is in the second column.

Author(s)

Karline Soetaert <karline.soetaert@nioz.nl>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# save plotting parameters
 pm <- par("mfrow")

## =======================================================================
## Create three dummy matrices
## =======================================================================

 M1 <- matrix(nrow = 10, ncol = 5, data = 1:50)
 colnames(M1) <- LETTERS[1:5]

 M2 <- M1[, c(1, 3, 4, 5, 2)] 
 M2[ ,-1] <- M2[,-1] /2
 colnames(M2)[3] <- "CC"  # Different name

 M3 <- matrix(nrow = 5, ncol = 4, data = runif(20)*10) 
 M3[,1] <- sort(M3[,1])
 colnames(M3) <- colnames(M1)[-3]

# show them
 head(M1); head(M2); head(M3)
 Msummary(M1)
 Msummary(M1, M2, M3)

# plot all columns of M3 -  will change mfrow 
 Mplot(M3, type = "b", pch = 18, col = "red")

# plot results of all three data sets
 Mplot(M1, M2, M3, lwd = 2, mtext = "All variables versus 1st column",
       legend = list(x = "top", legend = c("M1", "M2", "M3")))


## =======================================================================
## Plot a selection or only common elements
## =======================================================================

 Mplot(M1, M2, M3, x = "B", select = c("A", "E"), pch = c(NA, 16, 1), 
       type = c("l", "p", "b"), col = c("black", "red", "blue"),  
       legend = list(x = "right", legend = c("M1", "M2", "M3")))

 Mplot(Mcommon(M1, M2, M3), lwd = 2, mtext = "common variables", 
       legend = list(x = "top", legend = c("M1", "M2", "M3")))

 Mdescribe(Mcommon(M1, M2, M3))
 
## =======================================================================
## The iris and Orange data set
## =======================================================================

# Split the matrix according to the species
 Irislist <- Msplit(iris, split = "Species")
 names(Irislist)
 
 Mdescribe(Irislist, which = "Sepal.Length")
 Mdescribe(iris, which = "Sepal.Length", subset = Species == "setosa")

# legend in a separate plot
 Mplot(Irislist, type = "p", pos.legend = 0,
       legend = list(x = "center", title = "species"))

 Mplot(Msplit(Orange,1), lwd = 2,
       legend = list(x = "topleft", title = "tree nr"))
 Msummary(Msplit(Orange,1))

# reset plotting parameters
 par(mfrow = pm)

Example output

Loading required package: plot3D
Loading required package: plot3Drgl
Loading required package: rgl
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl_init' failed, running with rgl.useNULL = TRUE 
3: .onUnload failed in unloadNamespace() for 'rgl', details:
  call: fun(...)
  error: object 'rgl_quit' not found 
     A  B  C  D  E
[1,] 1 11 21 31 41
[2,] 2 12 22 32 42
[3,] 3 13 23 33 43
[4,] 4 14 24 34 44
[5,] 5 15 25 35 45
[6,] 6 16 26 36 46
     A    C   CC    E   B
[1,] 1 10.5 15.5 20.5 5.5
[2,] 2 11.0 16.0 21.0 6.0
[3,] 3 11.5 16.5 21.5 6.5
[4,] 4 12.0 17.0 22.0 7.0
[5,] 5 12.5 17.5 22.5 7.5
[6,] 6 13.0 18.0 23.0 8.0
             A        B        D         E
[1,] 0.1333254 6.230784 4.620234 0.3955672
[2,] 0.4143292 4.042282 7.009049 0.7150561
[3,] 1.4610300 9.508436 8.441904 9.2951367
[4,] 5.4622371 1.664132 4.520022 7.1983151
[5,] 7.3485925 9.361558 7.748918 6.4680072
  variable factor_or_char Min. X1st.Qu. Median Mean X3rd.Qu. Max.
1        A          FALSE    1     3.25    5.5  5.5     7.75   10
2        B          FALSE   11    13.25   15.5 15.5    17.75   20
3        C          FALSE   21    23.25   25.5 25.5    27.75   30
4        D          FALSE   31    33.25   35.5 35.5    37.75   40
5        E          FALSE   41    43.25   45.5 45.5    47.75   50
   variable object factor_or_char       Min.   X1st.Qu.    Median      Mean
1         A     M1          FALSE  1.0000000  3.2500000  5.500000  5.500000
2         A     M2          FALSE  1.0000000  3.2500000  5.500000  5.500000
3         A     M3          FALSE  0.1333254  0.4143292  1.461030  2.963903
4         B     M1          FALSE 11.0000000 13.2500000 15.500000 15.500000
5         B     M2          FALSE  5.5000000  6.6250000  7.750000  7.750000
6         B     M3          FALSE  1.6641319  4.0422818  6.230784  6.161438
7         C     M1          FALSE 21.0000000 23.2500000 25.500000 25.500000
8         C     M2          FALSE 10.5000000 11.6250000 12.750000 12.750000
9         D     M1          FALSE 31.0000000 33.2500000 35.500000 35.500000
10        D     M3          FALSE  4.5200216  4.6202340  7.009049  6.468026
11        E     M1          FALSE 41.0000000 43.2500000 45.500000 45.500000
12        E     M2          FALSE 20.5000000 21.6250000 22.750000 22.750000
13        E     M3          FALSE  0.3955672  0.7150561  6.468007  4.814416
14       CC     M2          FALSE 15.5000000 16.6250000 17.750000 17.750000
    X3rd.Qu.      Max.
1   7.750000 10.000000
2   7.750000 10.000000
3   5.462237  7.348593
4  17.750000 20.000000
5   8.875000 10.000000
6   9.361558  9.508436
7  27.750000 30.000000
8  13.875000 15.000000
9  37.750000 40.000000
10  7.748918  8.441904
11 47.750000 50.000000
12 23.875000 25.000000
13  7.198315  9.295137
14 18.875000 20.000000
  variable object factor_or_char  n missing unique      Mean       Sd
1        A     M1          FALSE 10       0     10  5.500000 3.027650
2        A     M2          FALSE 10       0     10  5.500000 3.027650
3        A     M3          FALSE  5       0      5  2.963903 3.249550
4        B     M1          FALSE 10       0     10 15.500000 3.027650
5        B     M2          FALSE 10       0     10  7.750000 1.513825
6        B     M3          FALSE  5       0      5  6.161438 3.397225
7        E     M1          FALSE 10       0     10 45.500000 3.027650
8        E     M2          FALSE 10       0     10 22.750000 1.513825
9        E     M3          FALSE  5       0      5  4.814416 4.025704
         Min      p0.05       p0.1      p0.5      p0.9     p0.95       Max
1  1.0000000  1.4500000  1.9000000  5.500000  9.100000  9.550000 10.000000
2  1.0000000  1.4500000  1.9000000  5.500000  9.100000  9.550000 10.000000
3  0.1333254  0.1895262  0.2457269  1.461030  6.594050  6.971321  7.348593
4 11.0000000 11.4500000 11.9000000 15.500000 19.100000 19.550000 20.000000
5  5.5000000  5.7250000  5.9500000  7.750000  9.550000  9.775000 10.000000
6  1.6641319  2.1397619  2.6153919  6.230784  9.449685  9.479061  9.508436
7 41.0000000 41.4500000 41.9000000 45.500000 49.100000 49.550000 50.000000
8 20.5000000 20.7250000 20.9500000 22.750000 24.550000 24.775000 25.000000
9  0.3955672  0.4594650  0.5233628  6.468007  8.456408  8.875772  9.295137
[1] "setosa"     "versicolor" "virginica" 
      variable     object factor_or_char  n missing unique  Mean        Sd Min
1 Sepal.Length     setosa          FALSE 50       0     15 5.006 0.3524897 4.3
2 Sepal.Length versicolor          FALSE 50       0     21 5.936 0.5161711 4.9
3 Sepal.Length  virginica          FALSE 50       0     21 6.588 0.6358796 4.9
  p0.05 p0.1 p0.5 p0.9 p0.95 Max
1 4.400 4.59  5.0 5.41 5.610 5.8
2 5.045 5.38  5.9 6.70 6.755 7.0
3 5.745 5.80  6.5 7.61 7.700 7.9
      variable factor_or_char  n missing unique  Mean        Sd Min p0.05 p0.1
1 Sepal.Length          FALSE 50       0     15 5.006 0.3524897 4.3   4.4 4.59
  p0.5 p0.9 p0.95 Max
1    5 5.41  5.61 5.8
        variable object factor_or_char Min. X1st.Qu. Median      Mean X3rd.Qu.
1            age      1          FALSE  118    574.0   1004 922.14286   1301.5
2            age      2          FALSE  118    574.0   1004 922.14286   1301.5
3            age      3          FALSE  118    574.0   1004 922.14286   1301.5
4            age      4          FALSE  118    574.0   1004 922.14286   1301.5
5            age      5          FALSE  118    574.0   1004 922.14286   1301.5
6  circumference      1          FALSE   30     72.5    115  99.57143    131.0
7  circumference      2          FALSE   33     90.0    156 135.28571    187.5
8  circumference      3          FALSE   30     63.0    108  94.00000    127.0
9  circumference      4          FALSE   32     87.0    167 139.28571    194.0
10 circumference      5          FALSE   30     65.0    125 111.14286    158.0
   Max.
1  1582
2  1582
3  1582
4  1582
5  1582
6   145
7   203
8   140
9   214
10  177

OceanView documentation built on July 12, 2021, 9:06 a.m.

Related to Mplot in OceanView...