batchPlot.list: Plot a Set of Curves from a List of Data

Description Usage Arguments Examples

Description

A simple utility method for visualizing a list of data.

Usage

1
2
3
4
5
6
7
8
batchPlot.list(data, xfun = function(x) x$x, yfun = function(x) x$y,
  ffun = function(x) x$f, plotXY = TRUE, widthXY = 0.5,
  plotXF = TRUE, widthXF = 1.5, names = NULL,
  colors = colors.distinct(length(data)), xlab = "", ylab = "",
  legend = NULL, x.min.lower = NA, x.min.upper = NA,
  x.max.lower = NA, x.max.upper = NA, y.min.lower = NA,
  y.min.upper = NA, y.max.lower = NA, y.max.upper = NA,
  x.add = NULL, XYType = "p", XFType = "l", ...)

Arguments

data

the data object, could be a list of lists or anything

xfun

a function which receives an element from the data list and extracts a vector of x-coordinates from it

yfun

a function which receives an element from the data list and extracts a vector of y-coordinates from it to be plotted as points, or NULL if no points should be plotted (see plotXY)

ffun

a function which receives an element from the data list and extracts a unary function from it to be plotted over the extracted x coordinates, or NULL if no points should be plotted (see plotXF)

plotXY

should the x-y points be plotted (if yfun is not NULL)

widthXY

the line width for points to be plotted (only considered if plotXY is TRUE and yfun is not NULL)

plotXF

should the x-y lines be plotted (if ffun is not NULL)

widthXF

the line width for lines to be plotted (only considered if plotXF is TRUE and ffun is not NULL)

names

the names of the lines to be printed in the legend, or NULL if no legend should be plotted

colors

the colors to be used for the plot

xlab

the label for the x-axis

ylab

the label for the y-axis

legend

a list of additional parameters to be passed to legend, or NULL to use the default parameters

x.min.lower

a lower bound for the automatically computed x coordinate minimum

x.min.upper

an upper bound for the automatically computed x coordinate minimum

x.max.lower

a lower bound for the automatically computed x coordinate maximum

x.max.upper

an upper bound for the automatically computed x coordinate maximum

y.min.lower

a lower bound for the automatically computed y coordinate minimum

y.min.upper

an upper bound for the automatically computed y coordinate minimum

y.max.lower

a lower bound for the automatically computed y coordinate maximum

y.max.upper

an upper bound for the automatically computed y coordinate maximum

x.add

some additional x coordinates at which the function should be evaluated, or TRUE if the x coordinate minimum and maximum over all data sets should be added as evaluation points

XYType

the type in which the XY data should be plotted, by default "p", i.e., as points

XFType

the type in which the XF data should be plotted, by default "l", i.e., as lines

...

Arguments passed on to graphics::plot

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
library(plotteR)

# set a random seed for replicability
set.seed(1367);

# make an example
make.example <- function(f) {
  n <- as.integer(round(runif(n=1, min=10, max=200)));
  x <- sort(runif(n=n, min=0, max=3)); # generate x data
  y <- rnorm(n=n, mean=f(x), s=0.1);  # noisy y
  x <- rnorm(n=n, mean=x, s=0.1); # noisy x
  return(list(x=x, y=y, f=f));
}

# the three base functions
f <- c(function(x) 1 - 0.2*x + 0.75*x*x - 0.3*x*x*x,
       function(x) 0.1 * exp(3 - x),
       function(x) 1.2 + 0.7*sin(2*x));

# create the three example data sets
examples <- lapply(X=f, FUN=make.example);

# plot the original data
batchPlot.list(examples,
               names=c("f1", "f2", "f3"),
               main="Original Data and Function Values for x",
               legend=list(x="bottom", horiz=TRUE));
library(plotteR)

# set a random seed for replicability
set.seed(1367);

# make an example
make.example <- function(f) {
  suppressWarnings({
    repeat {
      n <- as.integer(round(runif(n=1, min=10, max=20)));
      x <- sort(runif(n=n, min=-5, max=5)); # generate x data
      y <- rnorm(n=n, mean=f(x), s=0.1);  # noisy y
      x <- rnorm(n=n, mean=x, s=0.1); # noisy x
      fi <- is.finite(x) & is.finite(y);
      x <- x[fi];
      if(length(x) > 4L) {
        y <- y[fi];
        return(list(x=x, y=y, f=f));
      }
    }
  });
}

# the three base functions
f <- c(function(x) 1 - 0.2*x + 0.75*x*x - 0.3*x*x*x,
       log,   # this function becomes non-finite for x <= 0
       asin); # non-finite for any x outside of [-1, 1]

# create the three example data sets
examples <- lapply(X=f, FUN=make.example);

old <- par(mfcol=c(2, 1));

# plot the original data, which only covers part of the x.axis
batchPlot.list(examples,
               names=c("f1", "f2", "f3"),
               main="Original Data and Function Values for x",
               legend=list(x="left"),
               y.min.lower = -3,
               y.max.upper= 3);
abline(v=-1, col="gray");abline(v=0, col="gray");abline(v=1, col="gray");


# extending the function lines towards their smallest and largest finite
# points
batchPlot.list(examples,
               names=c("f1", "f2", "f3"),
               main="Functions Extented by Finite Point Search",
               legend=list(x="left"),
               y.min.lower = -3,
               y.max.upper= 3,
               x.add = TRUE);
abline(v=-1, col="gray");abline(v=0, col="gray");abline(v=1, col="gray");

par(old);

thomasWeise/plotteR documentation built on May 29, 2019, 5:41 a.m.