thanks for the response.
Uwe Ligges wrote:
joerg van den hoff wrote:
something like
matplot2(matrix(1:6,3,2),matrix(7:12,3,2),pch=21,bg=c(2,3),type='b')
Where can we find "matplot2"?
oops. that should have been 'matplot' (not 'matplot2'), of course.
does not yield the expected (at least by me) result: only the points
on the first line get (successively) background colors for the
plotting symbols, the second line gets no background color at all for
its plotting symbols.
I think the natural behaviour should be two curves which (for the
example given above) symbol-background colors 2 and 3, respectively
(as would be obtained by a suitable manual combination of 'plot' and
'lines'). the modification of the matplot code to achieve this
behaviour is obvious as far as I can see (adding 'bg' to the explicit
arguments of matplot and handling similar to 'lty', 'cex' and the like
inside the function including transfer to 'plot' and 'lines' argument
list).
is the present behaviour a bug of 'matplot' or is it for some reason
intended behaviour?
The real point is that you might want to mark by rows *or* by columns,
so it's not that easy to specify a sensible default behaviour, at least
one has to think about it.
I'm aware of this: any specific behaviour could be the 'best' default
for someone. in terms of consistency, I would argue that matplot plots
"columns of x against columns of y", so these columns should be
addressed. that is how 'lty' and 'pch' and 'cex' do it. the present
behaviour of 'bg' ('bg' interpreted only for "column 1 of x against
column 1 of y") is not sensible.
If you want to implement it for all possible arguments, the well known
problem of huge number of arguments springs to mind as well.
that is indeed a problem, but I think mainly when reading the help
pages, which then are cluttered with many not often used graphic parameters.
Since you say the "modification [...] is obvious": I think R-core
welcomes your contribution.
well, I'm not a fluent R programmer. I'm not sure if the simple minded
modification of 'matplot' would be welcome by R-core. rather, I attach
here the modified code 'matplot2' (sic!), if someone wants to use it. a
'diff' vs. the original versions shows easily the few modified lines.
joerg
Uwe Ligges
regards,
joerg
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
#clone of the standard 'matplot' version augmented by using 'bg' as an
#additional explicit argument and modifications of the code leading to
#a bevaviour of 'bg' similar to 'lty', 'pch', 'cex' et cetera (columnwise
#recycling of 'bg' entries).
matplot2 <- function (x, y, type = "p", lty = 1:5, lwd = 1, pch = NULL, col =
1:6,
cex = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, bg=NULL,
..., add = FALSE, verbose = getOption("verbose"))
{
paste.ch <- function(chv) paste("\"", chv, "\"", sep = "",
collapse = " ")
str2vec <- function(string) {
if (nchar(string)[1] > 1)
strsplit(string[1], NULL)[[1]]
else string
}
xlabel <- if (!missing(x))
deparse(substitute(x))
ylabel <- if (!missing(y))
deparse(substitute(y))
if (missing(x)) {
if (missing(y))
stop("Must specify at least one of `x' and `y'")
else x <- 1:NROW(y)
}
else if (missing(y)) {
y <- x
ylabel <- xlabel
x <- 1:NROW(y)
xlabel <- ""
}
kx <- ncol(x <- as.matrix(x))
ky <- ncol(y <- as.matrix(y))
n <- nrow(x)
if (n != nrow(y))
stop("`x' and `y' must have same number of rows")
if (kx > 1 && ky > 1 && kx != ky)
stop("`x' and `y' must have only 1 or the same number of columns")
if (kx == 1)
x <- matrix(x, nrow = n, ncol = ky)
if (ky == 1)
y <- matrix(y, nrow = n, ncol = kx)
k <- max(kx, ky)
type <- str2vec(type)
if (is.null(pch))
pch <- c(paste(c(1:9, 0)), letters)[1:k]
else if (is.character(pch))
pch <- str2vec(pch)
if (verbose)
cat("matplot: doing ", k, " plots with ", paste(" col= (",
paste.ch(col), ")", sep = ""), paste(" pch= (", paste.ch(pch),
")", sep = ""), " ...\n\n")
ii <- match("log", names(xargs <- list(...)), nomatch = 0)
log <- if (ii != 0)
xargs[[ii]]
xy <- xy.coords(x, y, xlabel, ylabel, log = log)
xlab <- if (is.null(xlab))
xy$xlab
else xlab
ylab <- if (is.null(ylab))
xy$ylab
else ylab
xlim <- if (is.null(xlim))
range(xy$x[is.finite(xy$x)])
else xlim
ylim <- if (is.null(ylim))
range(xy$y[is.finite(xy$y)])
else ylim
if (length(type) < k)
type <- rep(type, length.out = k)
if (length(lty) < k)
lty <- rep(lty, length.out = k)
if (length(lwd) < k)