##### Some simple 2-D plots of geometric objects in R ##### library(MASS) # eqscplot(), lda(), etc. library(mvtnorm) # rmvnorm(), dmvnorm(), etc. oldpar<-par(no.readonly=T) # First of all, we establish an empty plot that is big enough # to hold all of the data. # For this example, we pretend we have data in a matrix called X, # so first we make a dummy matrix: X <- matrix(c(0,5,0,10),ncol=2) # The first question in plotting "geometric objects" is whether # we want to try to preserve an isometric geometry, or whether # we want a more efficient use of the display area. # We have plot(X,,type='n', xlim=c(min(X[,1]),max(X[,1])), ylim=c(min(X[,2]),max(X[,2])), xlab=expression(x[1]),ylab=expression(x[2])) # or, to put the coordinate axes on the same scale, plot(X,,type='n', xlim=c(min(X),max(X)), ylim=c(min(X),max(X)), xlab=expression(x[1]),ylab=expression(x[2])) ####### Lines # To draw a line on the existing plot, we can use # lines() for two points, p1 and p2, or # abline() for a line given in intercept-slope form, (a,b). # lines() draws a line through two points (or lines segments through points). # abline() draws a line across the full plot surface. # We can distinguish 4 tasks: # given two points, # 1. draw a line to connect them: # use lines() directly # 2. draw a line across the full plot surface: # determine the slope and intercept and use abline(); # if the slope is infinite, use abline(v= ) # given slope and intercept, # 3. draw a line across the full plot surface: # use abline() directly # 4. draw a line segment (limited in some way): # determine relevant points and use lines() # For the point setup, let p1=(x1,y1) and p2=(x2,y2). # For task 1., # the values are passed to lines() in the form (x1,x2), (y1,y2). # For task 2., # the slope is # b = (y2-y1)/(x2-x1) # and the intercept is # a = y1 - b*x1 # Given the slope and intercept, a and b, and the limits # on x, x1