Created
September 7, 2012 15:20
-
-
Save cdesante/3667108 to your computer and use it in GitHub Desktop.
Plotting asymmetric dyad data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.