#' Simple function for placing text labels in the corner of a figure.
#' @description Designed for labelling figures in the corner with 'A', 'B', and so on. Finds the coordinates for you.
#' @export
#' @examples
#'
#' o <- par(mfrow=c(1,2))
#' with(iris, {
#' plot(Sepal.Width, Sepal.Length, panel.last=add_corner_label("A","topleft"))
#' plot(Petal.Width, Petal.Length, panel.last=add_corner_label("B","topleft"))
#' })
#' par(o)
add_corner_label <- function(txt, where, inset=0.08, inset.x=inset, inset.y=inset, log.y=FALSE, log.x=FALSE,...){
u <- par()$usr
if(grepl("left",where))x <- u[1] + inset.x*(u[2]-u[1])
if(grepl("right",where))x <- u[2] - inset.x*(u[2]-u[1])
if(grepl("bottom",where))y <- u[3] + inset.y*(u[4]-u[3])
if(grepl("top",where))y <- u[4] - inset.y*(u[4]-u[3])
if(log.x)
x <- 10^x
if(log.y)
y <- 10^y
text(x,y,txt,...)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.