Couples are scattered; one versus many

Is there an easy way to create a graph pairsthat compares only one variable with many others? In other words, can I build only one row or column of the standard scattering matrix pairswithout using a loop?

+4
source share
3 answers

Fuse your data, then use ggplot with a 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

+5
source

I will dfget around it with the base build option (using 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 possible, it is still a loop using Map.

+4
source

, lattice ( @zx8754 "df_melt" ):

library(lattice)

xyplot(value ~ x | variable, data = df_melt, layout = c(3,1), 
       between = list(x=1))

enter image description here

+3

All Articles