Thursday, November 19, 2020

xyplot

An X-Y plot is also known as a scatter plot. You have your basic splash of points that you hope will exhibit some sort of pattern, which you can then use to predict something. You may need to create a fit line as a guide to a probably value of Y given X (and vice versa). Either way, the one you pick is the independent variable, and the one you look up based on the one you picked is the dependent variable (you nearly always have X as the independent variable).

Of course since I noted that it's usually between two variables, I read down in the Wikipedia article where it talks about multivariate scatter plots. Go figure.

You can use scatter plots whenever you have data. Remember though, that extrapolating outside of the cloud of data is fraught with danger. You cannot predict with any accuracy the value of a dependent variable based on an independent variable value which is either less than the smallest, or greater than the greatest value in the plot. Period.

R Example

Use the lattice:xyplot function to create scatter plots. The R docs have xyplot in the same topic as dotplot, barchart, and more. Plenty of options, but you really only need the name of a qualifying dataset.

This example creates a simple graph that plots height (as X) against weight (as Y) using the women dataset. 

> library(lattice)
> xyplot(weight ~ height, data = women)

There is no men dataset. I guess that would be pointless.

No comments:

Post a Comment

Please help to combat malicious use of the Internet.