x.max <- 10 y.max <- 10 y1 <- 2 y2 <- 7.8 vector.y <- c(y1, y2) vector.x <- c(2, 5, 8) vector.xx <- c(0.5, 3.5, 6.5, 9.5) al <- (y2 - y1) * 0.3 m.y <- mean(vector.y) xy.rand <- data.frame( "x" = runif(1000, 0, x.max), "y" = runif(1000, m.y - 0.7, m.y + 0.7) ) # ----------------------------------------------------------------------------------- set.frame <- function() { par(mar = c(0, 0, 0, 0)) plot( numeric(0), numeric(0), xlim = c(0, x.max), ylim = c(0, x.max), axes = FALSE, xlab = "", ylab = "" ) } set.line <- function(vector.x, vector.y, margin.width = 1.3) { x <- range(vector.x) + c(-margin.width, margin.width) for (y in vector.y) { lines(c(0, x.max), c(y, y), lty = 3, lwd = 2) lines(x, c(y, y), lty = 1, lwd = 2) } } set.points <- function(y, pch, bg) { points( vector.x, rep(y, length(vector.x)), cex = 8, pch = pch, col = "#000000", bg = bg ) } set.arrows <- function(vector.x, y.start, y.end) { for (x in vector.x) { arrows( x, y.start, x, y.end, lwd = 2, col = "#666666" ) } } set.cloud <- function(xy.rand) { points( xy.rand$x, xy.rand$y, pch = "/", col = "#999999" ) } set.status <- function(vector.x, y, key) { sapply( 1:length(vector.x), function(i) { text( vector.x[i], y, eval(parse(text = sprintf("expression(%s[%i])", key, i) )), cex = 2, adj = c(0.4, 0.5) ) } ) } plot.schema <- function() { set.frame() set.line(vector.x, vector.y) set.points(y1, 21, "#ff8000") set.points(y2, 22, "#ffff00") set.arrows(vector.x, m.y + al, m.y - al) set.cloud(xy.rand) text(0, y1 - 1.6, "Observable world (data)", pos = 4, cex = 1.5) text(0, y2 + 1.8, "Real world (population)", pos = 4, cex = 1.5) set.status(vector.x, y2, "x") set.status(vector.x, y1, "y") } plot.interactons <- function(vector.x, y, w1, w2, col = "#0000ff") { for (x in vector.x) { arrows(x - w1, y, x - w2, y, lwd = 3, col = col) arrows(x + w1, y, x + w2, y, lwd = 3, col = col) points(x, y, pch = "?", cex = 1.5, col = col) } } # ----------------------------------------------------------------------------------- plot.schema() plot.interactons(vector.xx, y2 + 0.6, 0.2, 0.8)