Skip to content

text(x,y,greek character)

2 messages · Roy Little, Marc Schwartz

#
Dear list,
I would like to plot points with two types of labels, one at the data 
point (the name of the point) and another offset a bit with another 
factor which is either of the two greek characters alpha or beta. I have 
tried to get the routine to plot a greek character with expression() or 
with substitute() and have not yet had any success.  The following only 
plots the word in english in plain text. Here is my subroutine and data:

---------------------------------------------------
vmat<-as.matrix(read.table("vmat"))
Xm<-vmat[1:22,1:20]
hemd<-read.table("threehem",header=T)
Ym<-as.matrix(hemd[,2])
gvdw.pls<-plsr(Ym ~ Xm,6,method="kernelpls")
rsltv<-predict(gvdw.pls,comps=6)
plot(Ym,rsltv,type="n",xlab="Actividad + 
Biol??gica",xlim=c(4.6,6),ylim=c(4.8,6),ylab=" Act. + 
Biol.(Pred.)",main="QSAR Ligaci??n de Derivados de la Artemisina con + 
Hemina",sub="Descriptores de Coeficientes VdW")

text(Ym,rsltv,labels=threehem$cpd)
text(Ym,rsltv,labels=hemd$type,adj=c(0,-1))
---------------------------------------------
threehem:
"cpd" "ba" "deox" "ox" "hemin" "type"
"1" 1 4.89 -5.32 -5.11 -5.18 alpha
"2" 2 4.89 -5.12 -4.92 -5.12 beta
"3" 3 5.41 -5.62 -5.41 -5.56 alpha
"4" 4 5.47 -5.34 -5.09 -5.3 beta
"5" 5 5.21 -5.41 -5.12 -5.36 beta
"6" 6 5.28 -5.44 -5.14 -5.39 beta
"7" 7 5.16 -5.47 -5.17 -5.39 beta
"8" 8 4.8 -5.43 -5.03 -5.41 beta
"9" 9 4.92 -5.17 -4.9 -5.12 beta
"10" 10 5.02 -5.29 -4.94 -5.35 beta
"11" 11 5.18 -5.72 -5.38 -5.68 alpha
"12" 12 5.44 -5.53 -5.39 -5.66 alpha
"13" 13 5.71 -5.93 -5.64 -5.86 alpha
"14" 14 5.74 -6.01 -5.78 -5.91 alpha
"15" 15 5.75 -5.79 -5.61 -5.71 alpha
"16" 16 5.87 -5.97 -5.67 -5.94 alpha
"17" 17 5.37 NA NA -6.49 alpha
"18" 18 5.75 NA NA -6.5 alpha
"19" 19 5.04 -5.26 NA -5.17 beta
"20" 20 4.89 -5.04 -4.75 -4.98 beta
"21" 21 5.81 -5.71 NA -5.87 alpha
"22" 22 5.62 -6.11 NA -6.23 alpha
----------------------------------
I have included the Xm matrix of predictors as an attachment.
Thank you very much for your help.

Roy Little
Dept. Chem.
Facultad de Ciencias
Universidad de los Andes
M??rida, Venezuela

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: vmat
Url: https://stat.ethz.ch/pipermail/r-help/attachments/20051010/894900e0/vmat.pl
#
On Mon, 2005-10-10 at 07:59 -0400, Roy Little wrote:
<snip of data>

I believe I have a solution for you, but you may want to consider the
presentation, as it gets a bit busy. Perhaps consider using two colors
for the numeric text, where each color represents either alpha or beta
and then indicate this in a legend.

This could be done using:

cols <- ifelse(hemd$type == "alpha", "red", "blue")
text(Ym,rsltv,labels=hemd$cpd, col = cols)
legend("topleft", 
       legend = c(expression(alpha), expression(beta)), 
       fill = c("red", "blue"))


Also, two notes:

1. If you are going to use a function that is not in the base R
distribution, please indicate this so that folks can help without having
to search. In this case, the plsr() function is in the pls package,
which required a library(pls) before using your code.


2. The line: 

  text(Ym,rsltv,labels=threehem$cpd)

should be:

  text(Ym,rsltv,labels=hemd$cpd)


Here is a solution:

   greek <- parse(text = as.character(hemd$type))

   text(Ym, rsltv, labels = greek, adj=c(0, -1))

hemd$type is a factor, so it needs to be converted to a character vector
before being able to be used as an expression. Using parse() then
converts the character vector to an expression. The result of the first
line is:
expression(alpha, beta, alpha, beta, beta, beta, beta, beta, 
    beta, beta, alpha, alpha, alpha, alpha, alpha, alpha, alpha, 
    alpha, beta, beta, alpha, alpha)

Thus, 'greek' can be used in text() as an expression.

HTH,

Marc Schwartz