So the problem is creating a line graph representing the interaction.
To do this, you need to format your data in the appropriate form. You want to build segments, and for this you need the coordinates of each segment on one line in your data frame:
interaction <- merge(propdata, relation, by.x="name", by.y="name1") interaction <- cbind(interaction, merge(propdata, relation, by.x="name", by.y="name2")[, c("X", "Y")]) names(interaction)[8:9] <- c("Xend", "Yend") interaction name diameter XY colr name2 score Xend Yend 1 A 4.3 1 1 10 B 1.1 2 3 2 A 4.3 1 1 10 C 2.2 3 3 3 A 4.3 1 1 10 D 5.4 3 3 4 B 8.3 2 3 20 C 3.1 4 4 5 B 8.3 2 3 20 D 2.0 4 4
Now we are facing another problem. In ggplot2 you can only have a scale of one size. Since you have a size argument for both the dot and the row, this really represents two things, this cannot be done without a workaround.
So the workaround is to draw circles manually using geom_polygon .
Build a data frame with circles:
circle <- function(x, y, d, color, scale=1){ d <- d * scale angle <- seq(-pi, pi, length = 50) data.frame( x = x + d/2*sin(angle), y = y + d/2*cos(angle), color=color) } circles <- ddply(propdata, .(name), function(x)with(x, circle(X, Y, diameter, colr, scale=0.2)))
Finally, create a graph:
ggplot() + geom_polygon(data=circles, aes(group=name, x=x, y=y, fill=color)) + geom_text(data=propdata, aes(x=X, y=Y, label=name), hjust=0, vjust=0) + geom_segment(data=interaction, aes(x=X, y=Y, xend=Xend, yend=Yend, size=score)) + scale_size("Inter", to=c(0, 5)) + coord_equal()
