Skip to content
Prev 350364 / 398506 Next

- Obtaining superscripts to affix to means that are not significantly different from each other with R

Hi Joachim,
This function allows the user to set some characters in a string to
superscript or subscript. If sup or sub are set to one or more numbers
corresponding to an index in the string, those letters will be placed
appropriately. I can't properly test this as there is some problem
with X11 fonts that has appeared with the upgrade to R 3.2.0 and the
cex argument seems to have no effect.

supsubtext<-function(x,y,label,sup=NA,sub=NA,cex=1,sscex=0.8,xadj=0,...) {
 nlabchar<-nchar(label)
 yadj<-rep(0.5,nlabchar)
 if(!is.na(sup)) yadj[sup]<-0
 if(!is.na(sub)) yadj[sub]<-1
 labbits<-strsplit(label,"")[[1]]
 currentx<-x
 for(labchar in 1:nlabchar) {
  text(x,y,labbits[labchar],adj=c(xadj,yadj[labchar]),
   cex=ifelse(yadj[labchar]!=0.5,sscex,cex),...)
  x<-x+strwidth(labbits[labchar])
 }
}

Jim


On Thu, Apr 23, 2015 at 11:02 PM, Joachim Audenaert
<Joachim.Audenaert at pcsierteelt.be> wrote:
Message-ID: <CA+8X3fXiqkWv0+vhrWbzwX+JpOa_CU4ARo1OyoVKANrrZJ5BUQ@mail.gmail.com>
In-Reply-To: <OF8860DA7E.2E8F2BA1-ONC1257E30.00478D42-C1257E30.0047A99B@pcsierteelt.be>