Skip to content

Instantly share code, notes, and snippets.

@cdesante
Created September 7, 2012 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdesante/3667108 to your computer and use it in GitHub Desktop.
Save cdesante/3667108 to your computer and use it in GitHub Desktop.
Plotting asymmetric dyad data
#This code produces a faceted plot of dyad-level data with asymmetry in the variable of interest across dyads.
MYDATA <- matrix(rnorm(16*16), 16, 16)
diag(MYDATA) <- rep(NA, 16)
MYDATA
colnames(MYDATA) <- rownames(MYDATA) <- LETTERS[1:16]
MYDATA
sender.row <- c()
receiver.col <- c()
value.to.plot <-c()
value.vector <-c()
value.to.add <- c()
rownames(MYDATA)[5]
MYDATA[i,j]
for (i in 1:16) {
for (j in 1:16) {
value.to.add <- MYDATA[i, j]
value.vector <- c(value.vector, MYDATA[i,j])
sender.row <- c(sender.row, rownames(MYDATA)[i])
receiver.col <- c(receiver.col, colnames(MYDATA)[j])
}
}
length(value.vector)
mat.to.plot <- cbind(value.vector, sender.row, receiver.col)
mat.to.plot
library(ggplot2)
qplot(sender.row, value.vector, geom="point") + facet_wrap(~receiver.col)
@dsparks
Copy link

dsparks commented Sep 7, 2012

I'm getting an error that says "Error in layout_base(data, vars, drop = drop) : At least one layer must contain all variables used for facetting." I'm trying to figure out what the problem is, but I thought I'd let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment