[R] "non-plot" plotting

Marc Schwartz marc_schwartz at comcast.net
Fri Jan 18 01:03:20 CET 2008


Johannes Graumann wrote:
> I really do not know ho to else title this ... I want to draw something like
> the attached png with R and would like to poll you on how to start ... make
> an empty plot first and then start positioning the characterstring
> by 'text' and then drawing the lines ...
>
> Joh

Johannes,

Try this (PDF of the output attached):

# Open the initial plot window and set
# up a coordinate system based upon
# placement of the letters centered
# on integer 'x' values 1:12
plot(1, xlim = c(0, 13), ylim = c(0, 4),
      type = "n",
      ann = FALSE, axes = FALSE)

# Create the vector of letters
Vec <- c("T", "V", "F", "S", "Q", "A", "Q",
          "L", "C", "A", "L", "K")

# Plot them
text(1:12, 2, Vec, cex = 2, font = 2)

# Get the height of the letters for spacing
# See ?strheight
height <- strheight("T", cex = 2) * .8

# Set a default width for the "boxes"
# around the letter
width <- 0.5

# Set the values for 'Y's
Y <- 10:2
X <- 3:11

# Loop over the Y's and using plotmath
# plot the values and subscripts in bold
# See ?plotmath and ?bquote
# While looping, do the colored segments
for (i in 1:9) {
   text(X[i], 2 + (height * 1.6), bquote(bold(Y[.(Y[i])])),
        col = "red", font = 2)

   x <- c(X[i] - width, X[i] - width, X[i] + 0.3)
   y <- c(2, 2 + height, 2 + height)

   lines(x, y, col = "red", lwd = 2)
}




# Same here now for the 'b's

b <- c(2:6, 8, 9, 11)
X <- b

for (i in 1:8) {
   text(X[i], 2 - (height * 1.6), bquote(bold(b[.(b[i])])),
        col = "blue", font = 2)

   x <- c(X[i] - 0.3, X[i] + width, X[i] + width)
   y <- c(2 - height, 2 - height, 2)

   lines(x, y, col = "blue", lwd = 2)
}



The above should provide the basic approach. You can then adjust/fine 
tune spacing, etc. as you require.

HTH,

Marc Schwartz

-------------- next part --------------
A non-text attachment was scrubbed...
Name: plot.pdf
Type: application/pdf
Size: 5063 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080117/473d224f/attachment-0002.pdf 


More information about the R-help mailing list