#==========================================================================================#
#==========================================================================================#
# cnvrt.coords was copied from Hmisc package. This function converts coordinates from #
# one type of input to all plot coordinates. #
#------------------------------------------------------------------------------------------#
cnvrt.coords <<- function(x,y=NULL,input=c("usr","plt","fig","dev")) {
#----- Grab the coordinates and inputs. ------------------------------------------------#
input = tolower(match.arg(input))
xy = xy.coords(x,y)
#---------------------------------------------------------------------------------------#
#---------------------------------------------------------------------------------------#
# Obtain plot information. #
#---------------------------------------------------------------------------------------#
cusr = par("usr")
cplt = par("plt")
cfig = par("fig")
#---------------------------------------------------------------------------------------#
#----- Compute "usr" unless this is the input. -----------------------------------------#
if (input == "usr"){
usr = xy
}else{
usr = list( x = plt$x*(cusr[2]-cusr[1])+cusr[1]
, y = plt$y*(cusr[4]-cusr[3])+cusr[3]
)#end list
}#end if
#---------------------------------------------------------------------------------------#
#----- Compute "plt" unless this is the input. -----------------------------------------#
if (input == "plt"){
plt = xy
}else{
plt = list( x = (xy$x-cusr[1])/(cusr[2]-cusr[1])
, y = (xy$y-cusr[3])/(cusr[4]-cusr[3])
)#end list
}#end if
#---------------------------------------------------------------------------------------#
#----- Compute "fig" unless this is the input. -----------------------------------------#
if (input == "fig"){
fig = xy
}else{
fig = list( x = plt$x*(cplt[2]-cplt[1])+cplt[1]
, y = plt$y*(cplt[4]-cplt[3])+cplt[3]
)#end list
}#end if
#---------------------------------------------------------------------------------------#
#----- Compute "dev" unless this is the input. -----------------------------------------#
if (input == "dev"){
dev = xy
}else{
dev = list( x = fig$x*(cfig[2]-cfig[1])+cfig[1]
, y = fig$y*(cfig[4]-cfig[3])+cfig[3]
)#end list
}#end if
#---------------------------------------------------------------------------------------#
#----- Create a list with all coordinates and leave. -----------------------------------#
ans = list(usr = usr, plt = plt, fig = fig, dev = dev)
return(ans)
#---------------------------------------------------------------------------------------#
}#end function cnvrt.coord
#==========================================================================================#
#==========================================================================================#
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.