Rutils/maybe-not-useful/out.text.r

#==========================================================================================#
#==========================================================================================#
#     This function creates a text with an outline.                                        #
#------------------------------------------------------------------------------------------#
out.text <<- function( x
                     , y      = NULL
                     , labels
                     , r      = 0.04
                     , nth    = 72
                     , border = "black"
                     , fill   = "white"
                     , cex    = 1.0
                     , ...
                     ){


   #----- Retrieve x and y. ---------------------------------------------------------------#
   if (is.null(y)){
      xy = x
   }else{
      xy = data.frame(x=x,y=y)
   }#end if
   #---------------------------------------------------------------------------------------#


   #----- Get the additional options. -----------------------------------------------------#
   dotdotdot = list(...)
   #---------------------------------------------------------------------------------------#


   #----- Retrierve some graphics info. ---------------------------------------------------#
   ps   = par("ps")
   plt  = par("plt") * rep(par("pin"),each=2)
   usr  = par("usr")
   xlog = par("xlog")
   ylog = par("ylog")
   #---------------------------------------------------------------------------------------#


   #----- Find the nudge radius and angle. ------------------------------------------------#
   hlet  = (usr[2]-usr[1]) / (plt[2]-plt[1]) * r * cex * ps / 72
   vlet  = (usr[4]-usr[3]) / (plt[4]-plt[3]) * r * cex * ps / 72
   theta = seq(from=0,to=2*pi,length=nth)
   #---------------------------------------------------------------------------------------#


   #----- Loop over all values of theta. --------------------------------------------------#
   for (th in theta){
       #-----------------------------------------------------------------------------------#
       #     Find the position of x and y.                                                 #
       #-----------------------------------------------------------------------------------#
       if (xlog){
          xnow = 10^(log10(xy$x)+hlet*cos(th))
       }else{
          xnow = xy$x + hlet * cos(th)
       }#end if
       if (ylog){
          ynow = 10^(log10(xy$y)+vlet*sin(th))
       }else{
          ynow = xy$y + vlet * cos(th)
       }#end if
       #-----------------------------------------------------------------------------------#



       #-----------------------------------------------------------------------------------#
       #    Arguments for this text.                                                       #
       #-----------------------------------------------------------------------------------#
       argsnow = modifyList( x   = dotdotdot
                           , val = list(x=xnow,y=ynow,labels=labels,cex=cex,col=border)
                           )#end modifyList
       dummy   = do.call(what="text",args=argsnow)
       #-----------------------------------------------------------------------------------#

   }#end for
   #---------------------------------------------------------------------------------------#


   #---------------------------------------------------------------------------------------#
   #    Last, plot the text in the centre.                                                 #
   #---------------------------------------------------------------------------------------#
   argsnow = modifyList( x   = dotdotdot
                       , val = list(x=xy$x,y=xy$y,labels=labels,cex=cex,col=fill)
                       )#end modifyList
   dummy   = do.call(what="text",args=argsnow)
   #---------------------------------------------------------------------------------------#

}#end function out.text
#==========================================================================================#
#==========================================================================================#
manfredo89/ED2io documentation built on May 21, 2019, 11:24 a.m.