ABCCoords.Rd
Return the xy.coordinates for the literal positions "bottomright", etc. as used to place legends.
ABCCoords(x = "topleft", region = "figure", cex = NULL, linset = 0, ...)
one out of "bottomright"
, "bottom"
, "bottomleft"
,
"left"
, "topleft"
, "top"
, "topright"
, "right"
, "center"
one out of plot
or figure
the character extension for the text.
line inset in lines of text.
the dots are passed to the strwidth()
and strheight()
functions in case there where more specific text formats.
The same logic as for the legend can be useful for placing texts, too. This function returns the coordinates for the text, which can be used in the specific text functions.
nothing returned
plot(x = rnorm(10), type="n", xlab="", ylab="")
# note that plot.new() has to be called before we can grab the geometry
ABCCoords("bottomleft")
#> $xy
#> $xy$x
#> [1] -0.74375
#>
#> $xy$y
#> [1] -3.346191
#>
#> $xy$xlab
#> NULL
#>
#> $xy$ylab
#> NULL
#>
#>
#> $adj
#> [1] 0 0
#>
lapply(c("bottomleft", "left"), ABCCoords)
#> [[1]]
#> [[1]]$xy
#> [[1]]$xy$x
#> [1] -0.74375
#>
#> [[1]]$xy$y
#> [1] -3.346191
#>
#> [[1]]$xy$xlab
#> NULL
#>
#> [[1]]$xy$ylab
#> NULL
#>
#>
#> [[1]]$adj
#> [1] 0 0
#>
#>
#> [[2]]
#> [[2]]$xy
#> [[2]]$xy$x
#> [1] -0.74375
#>
#> [[2]]$xy$y
#> [1] -0.719475
#>
#> [[2]]$xy$xlab
#> NULL
#>
#> [[2]]$xy$ylab
#> NULL
#>
#>
#> [[2]]$adj
#> [1] 0.0 0.5
#>
#>
plot(x = rnorm(10), type="n", xlab="", ylab="")
text(x=(xy <- ABCCoords("bottomleft", region = "plot"))$xy,
labels = "My Maybe Long Text", adj = xy$adj, xpd=NA)
text(x=(xy <- ABCCoords("topleft", region = "figure"))$xy,
labels = "My Maybe Long Text", adj = xy$adj, xpd=NA)
plot(x = rnorm(10), type="n", xlab="", ylab="")
sapply(c("topleft", "top", "topright", "left", "center",
"right", "bottomleft", "bottom", "bottomright"),
function(x)
text(x=(xy <- ABCCoords(x, region = "plot", linset=1))$xy,
labels = "MyMarginText", adj = xy$adj, xpd=NA)
)
#> $topleft
#> NULL
#>
#> $top
#> NULL
#>
#> $topright
#> NULL
#>
#> $left
#> NULL
#>
#> $center
#> NULL
#>
#> $right
#> NULL
#>
#> $bottomleft
#> NULL
#>
#> $bottom
#> NULL
#>
#> $bottomright
#> NULL
#>
plot(x = rnorm(100), type="n", xlab="", ylab="",
panel.first={Bg(c("red", "lightyellow"))
grid()})
xy <- ABCCoords("topleft", region = "plot")
par(xpd=NA)
BoxedText(x=xy$xy$x, y=xy$xy$y, xpad = 1, ypad = 1,
labels = "My Maybe Long Text", adj = xy$adj, col=SetAlpha("green", 0.8))