scatterplot() with scales

Today I spend quite some time trying to figure out why I couldn’t use the scatterplot function (from the package car) for one specific variable, while it worked for every other variable. I got stuck at the error “Error in if (transform != FALSE | length(transform) == ncol(x)) { : argument is of length zero.”

It was only when I used str on the variables to examine the structure that I realized that the scatterplot function does not work with scales. So, normally I could use scatterplot(y~x | country). In this particular case, I used x <- scale(x1) + scale(x2) +... to create the new variable. scatterplot(y~x1 | country) worked perfectly, as did scatterplot(y~x2 | country), but the scale did not. It turns out the scale function also adds additional information, which breaks the scatterplot function. Once I knew this, the solution seemed obvious: filter out this additional information by using as.numeric: scatterplot(y~as.numeric(x) | country).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: