简体   繁体   中英

R: Transformation of data with log10 qqline warning message the condition has length > 1 and only the first element will be used

I want to transform my data in R with a logarithm and want to plot it with a qqplot. I got the warning message, see below. What does this exactly mean for the plot?

log <-log10(life$p) 
qqplot(life$p,log, main = "Normal Q-Q Plot",plot.it = TRUE)
qqline(life$p,log, col="red")

The warning message was:

In if (datax) { :
the condition has length > 1 and only the first element will be used

There seem to be several things wrong here.

Your call to qqplot is almost certainly not doing what you wanted. Notice that the documentation ?qqplot says:

qqplot produces a QQ plot of two datasets.

Your code is:
qqplot(life$p,log, main = "Normal QQ Plot",plot.it = TRUE)
The "two datasets" that you are giving it are life$p and log, so this will plot the quantiles of life$p against the quantiles of log = log10(life$p). That makes no sense. Since your title says "Normal QQ Plot", I suspect that you wanted to plot log against a Normal distribution. To get that, you probably wanted:
qqnorm(log, main = "Normal QQ Plot")

Now to your error message.
The documentation for qqline gives the argument sequence as:

qqline(y, datax = FALSE, distribution = qnorm,
       probs = c(0.25, 0.75), qtype = 7, ...)

Your call to this function is:

qqline(life$p,log, col="red")

You don't name the arguments so they are interpreted in order. life$p is y and log is datax. datax is supposed to be a logical value (TRUE/FALSE), but you are passing it an array of numbers, hence the error message. I believe that what you intended was:

qqline(log, col="red")

Finally, log is the name of the natural logarithm function. It is a bad idea to name your variable log since it will be confusing if that refers to the function or the variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM