Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pairs scatter plot; one vs many [duplicate]

Tags:

r

Is there a parsimonious way to create a pairs plot that only compares one variable to the many others? In other words, can I plot just one row or column of the standard pairs scatter plot matrix without using a loop?

like image 273
andrew Avatar asked May 01 '15 07:05

andrew


People also ask

How do you interpret a scatter plot with multiple variables?

Interpreting scatter plotsCheck for negative relationships between the two variables in the plot. If you see low values for the first variable and high values of the second variable, there is a negative correlation. In this case, a line drawn through the data points will slope downwards i.e. a negative slope.

What are the 3 types of scatter plots?

The kind of correlation can be interpreted through the patterns revealed on a Scatterplot. These are: positive (values increase together), negative (one value decreases as the other increases) or null (no correlation). The shape of the correlation can be described as: linear, exponential and U-shaped.

Can a scatter plot have more than 2 variables?

You can have more than one dependent variable. Your data set might include more than one dependent variable, and you can still track this on a scatter plot. The only thing you'll want to change is the color of each dependent variable so that you can measure them against each other on the scatter plot.


2 Answers

Melt your data then use ggplot with facet.

library("ggplot2")
library("reshape2")

#dummy data
df <- data.frame(x=1:10,
                 a=runif(10),
                 b=runif(10),
                 c=runif(10))

#melt your data
df_melt <- melt(df,"x")

#scatterplot per group
ggplot(df_melt,aes(x,value)) +
  geom_point() +
  facet_grid(.~variable)

enter image description here

like image 158
zx8754 Avatar answered Oct 13 '22 01:10

zx8754


I'll round it out with a base plotting option (using df from @zx8754):

layout(matrix(seq(ncol(df)-1),nrow=1))
Map(function(x,y) plot(df[c(x,y)]), names(df[1]), names(df[-1]))

yeah

Although arguably this is still a loop using Map.

like image 41
thelatemail Avatar answered Oct 13 '22 00:10

thelatemail