New_to_this New_to_this - 11 days ago 10
R Question

Understanding do.call semantics based on "plot"

I'm fooling around with

do.call
.

I = iris
do.call(what = "plot", args = c(I$Sepal.Length ~ I$Sepal.Width))
# This seems fine

p = list(x = I$Sepal.Length, y = I$Sepal.Width)
do.call(what = "plot", args = p)
# This looks weird

p1 = list(x = I$Sepal.Length, y = I$Sepal.Width, xlab = "")
do.call(what = "plot", args = p1)
# A bit less weird


p2 = list(x = I$Sepal.Length, y = I$Sepal.Width, xlab = "", ylab = "")
do.call(what = "plot", args = p2)
# And this gives the same as the first do.call


So why is it, that I have to supply the axis labels to surpress all those numbers I get when using
do.call
?

Answer

What you are seeing is what R puts on the axis labels when it can't get any other naming info from the arguments. If you do:

plot(x=c(1,2,3,4,5,6,7,8),y=c(1,2,3,4,3,2,3,4))

then the plot will have to use the vector values as the axis labels.

When using do.call, the names in the list arguments are matched to the names of the arguments of the function called. So there's no names left for the axis labels, just the values. At that point the fact that the data came from I$Sepal.width is long gone, its just a vector of values.

Comments