[R] text(x,y,greek character)

2005-10-10 Thread Roy Little

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

-0.12 -0.18 -0.41 0.14 -0.21 0.15 -0.25 -0.41 -0.41 -0.29 -0.28 -0.27 -0.43 
-0.39 -0.43 -0.5 -0.3 -0.25 -0.4 0.06 4.89
-0.2 -0.16 -0.38 0.15 -0.2 0.15 -0.24 -0.42 -0.43 -0.3 -0.3 -0.29 -0.44 -0.39 
-0.43 -0.51 -0.27 -0.26 -0.41 0.19 4.89
-0.11 -0.19 -0.41 0.14 -0.21 0.14 -0.27 -0.4 -0.4 -0.29 -0.28 -0.26 -0.42 -0.38 
-0.44 -0.5 -0.3 -0.24 -0.4 0.03 5.41
-0.18 -0.16 -0.38 0.15 -0.2 0.15 -0.24 -0.42 -0.42 -0.31 -0.3 -0.29 -0.44 -0.39 
-0.43 -0.51 -0.27 -0.26 -0.41 0.19 5.47
-0.2 -0.16 -0.38 0.15 -0.2 0.15 -0.24 -0.42 -0.42 -0.31 -0.3 -0.29 -0.44 -0.39 
-0.43 -0.5 -0.27 -0.26 -0.4 0.19 5.21
-0.18 -0.16 -0.38 0.15 -0.2 0.15 -0.24 -0.42 -0.42 -0.31 -0.3 -0.29 -0.44 -0.39 
-0.43 -0.51 -0.27 -0.26 -0.4 0.19 5.28
-0.18 -0.16 -0.38 0.15 -0.2 0.15 -0.24 -0.42 -0.42 -0.31 -0.3 -0.29 -0.44 -0.39 
-0.43 -0.51 -0.27 -0.26 -0.41 0.19 5.16
-0.18 -0.16 -0.38 0.15 -0.21 0.15 -0.25 -0.42 -0.42 -0.31 -0.3 -0.29 -0.44 
-0.39 -0.43 -0.51 -0.27 -0.26 -0.4 0.19 4.8
-0.18 -0.16 -0.38 0.15 -0.2 0.15 -0.24 -0.42 -0.42 -0.31 -0.3 -0.29 -0.44 -0.39 
-0.43 -0.51 -0.27 -0.26 -0.4 0.19 4.92
-0.23 -0.14 -0.35 0.15 -0.2 0.15 -0.25 -0.4 -0.43 -0.33 -0.32 -0.3 -0.44 -0.39 
-0.41 -0.51 -0.24 -0.26 -0.39 0.18 5.02
-0.15 -0.22 -0.44 0.14 -0.21 0.13 -0.29 -0.39 -0.41 -0.26 -0.24 -0.22 -0.39 
-0.35 -0.44 -0.48 -0.33 -0.19 -0.39 -0.02 5.18
-0.12 -0.2 -0.42 0.14 -0.21 0.14 -0.28 -0.4 -0.41 -0.29 -0.27 -0.25 -0.41 -0.37 
-0.44 -0.49 -0.31 -0.22 -0.39 0 5.44
-0.14 -0.19 -0.42 0.14 -0.21 0.14 -0.26 -0.41 -0.41 -0.28 -0.26 -0.25 -0.42 
-0.39 -0.46 -0.49 -0.31 -0.23 -0.37 0.01 5.71
-0.16 -0.23 -0.44 0.14 -0.21 0.13 -0.29 -0.4 -0.4 -0.26 -0.23 -0.22 -0.4 -0.36 
-0.45 -0.48 -0.33 -0.19 -0.38 -0.02 5.74
-0.14 -0.23 -0.43 0.14 -0.21 0.14 -0.28 -0.39 -0.4 -0.28 -0.26 -0.24 -0.38 
-0.35 -0.42 -0.49 -0.32 -0.21 -0.39 -0.01 5.75
-0.14 -0.23 -0.43 0.14 -0.21 0.14 -0.28 -0.4 -0.4 -0.27 -0.25 -0.23 -0.37 -0.34 
-0.4 -0.48 -0.32 -0.2 -0.39 -0.01 5.87
-0.22 -0.15 -0.36 0.15 -0.2 0.16 -0.24 -0.44 -0.43 -0.26 -0.26 -0.27 -0.38 
-0.35 -0.32 -0.49 -0.27 -0.25 -0.34 0.05 5.37
-0.2 -0.27 -0.42 0.14 -0.2 0.15 -0.23 -0.34 -0.41 -0.28 -0.29 -0.28 -0.39 -0.34 
-0.28 -0.46 -0.32 -0.26 -0.26 0.05 5.75
-0.18 -0.16 -0.38 0.15 -0.21 0.15 -0.25 -0.41 -0.42 -0.31 -0.3 -0.29 -0.44 
-0.39 -0.43 -0.51 -0.27 -0.26 -0.4 0.19 5.04
-0.23 -0.13 -0.35 0.15 -0.2 0.16 -0.24 -0.41 -0.44 -0.32 -0.31 -0.3 -0.44 -0.39 
-0.41 -0.51 -0.25 -0.26 -0.41 0.19 4.89
-0.22 -0.09 -0.35 0.15 -0.2 0.15 -0.26 -0.45 -0.45 -0.28 -0.26 -0.25 -0.41 
-0.34 -0.36 -0.5 -0.27 -0.23 -0.34 0.01 5.81
-0.23 -0.13 -0.37 0.15 -0.2 0.14 -0.28 -0.43 -0.44 -0.26 -0.23 -0.22 -0.4 -0.33 
-0.39 -0.49 -0.28 -0.2 -0.34 -0.01 5.62
-0.12 -0.18 -0.41 0.14 -0.21 0.15 -0.25 -0.42 -0.41 -0.3 -0.29 -0.28 -0.43 
-0.43 -0.39 -0.51 -0.3 -0.26 -0.4 0.14 NA
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Re: [R] text(x,y,greek character)

2005-10-10 Thread Marc Schwartz
On Mon, 2005-10-10 at 07:59 -0400, Roy Little wrote:
 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))
 -

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:

 greek
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

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html