########################################################################## # # # Elementary version of an R function for drawing a Location-Spread plot # # # ########################################################################## location.spread.plot <- function(loc.in, # vector of location values sprd.in, # vector of spread values # loc.in and sprd.in must be of equal length ww = pretty(c(loc.in,sprd.in))[length(pretty(c(loc.in,sprd.in)))], # nice plotting range n.l = 10, # number of equally spaced, 45 degree reference rays # to be drawn. Set n.l <= 20 for best results col.plot = rep(1,length(loc.in)), # vector of plotting colors pch = 16, # plotting character xlab = "Location", # x-axis lable ylab = "Spread", # y-axis lable main = "Location-Spread Plot", # main title pin = 3 # height and half-width of the plot in inches ){ # store the current values of the graphics parameters op <- par(pin=c(2*pin,pin)) # set up the axes and labels plot(loc.in,sprd.in,xlim=c(-ww,ww),ylim=c(0,ww), xlab=xlab,ylab=ylab,main=main,type="n") # set up the colors for the 45 degree reference rays according to a heat # color map c.offset <- floor(n.l/4) col.l <- heat.colors(n.l+2*c.offset)[(n.l+c.offset):(c.offset+1)] # Make the background color of the quadrant delimited by the two main # diagonal through the origin a pale yellow a <- 0 b <- 0 d <- ww/(n.l-1) x <- c(a,a+ww,a-ww,a) y <- c(b,b+ww,b+ww,b) polygon(x,y, xpd=FALSE, col = heat.colors(30)[29], lty=2, lwd=2, border = NA) # Draw the 45 degree refence rays for(j in seq(1,n.l)){ x <- c(a+(j-1)*d,ww) y <- c(0,ww-(j-1)*d) lines(x,y,lty=1,col=col.l[j]) x <- c(a-(j-1)*d,-ww) y <- c(0,ww-(j-1)*d) lines(x,y,lty=1,col=col.l[j]) } # Draw a vertical reference ray through the origin lines(c(0,0),c(0,ww),col=col.l[n.l]) # Plot the location-spread points points(loc.in,sprd.in,pch=pch,col=col.plot) # Restore the original values of the graphics parameters par(op) }