coords | R Documentation |
Return the user plot, figure, inner, and device {x,y} coordinates
for a vector of normalized (i.e., in [0,1]
) coordinates. Or, if
line
and side
are given, the x (or y) user coordinates.
coords(x = 0:1, y = x, to = "user", line, side)
x, y |
normalized x- and y-coordinates in |
to |
character string giving the coordinate system to convert to |
line, side |
the margin line starting at 0 counting outwards and side
of the plot (1=below, 2=left, 3=above, 4=right); see |
convertXY
; mtext
op <- par(oma = 1:4, mar = 1:4, xpd = NA, pch = 16, xpd = NA)
plot.new()
box('plot', col = 1)
box('figure', col = 2)
box('outer', col = 3)
# box('inner', col = 4)
xx <- c(1,2,1,2)
yy <- c(1,1,2,2)
co <- coords()
points(co$plot$x[xx], co$plot$y[yy], cex = 5, col = 1)
points(co$figure$x[xx], co$figure$y[yy], cex = 5, col = 2)
points(co$device$x[xx], co$device$y[yy], cex = 5, col = 3)
co <- coords(seq(0, 1, 0.1), 1)
points(co$plot$x, co$plot$y, cex = 2, col = 4)
points(co$figure$x, co$figure$y, cex = 2, col = 5)
points(co$device$x, co$device$y, cex = 2, col = 6)
## use line/side for x or y coordinates depending on side
mtext('text', line = 1, side = 3, at = 0.5)
text(0.5, coords(line = 1, side = 3), 'text', col = 2)
mtext('text', line = -1:4, side = 4, at = 0.5)
text(coords(line = -1:4, side = 4), 0.5, 'text', col = 2, srt = 90)
par(op)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.