Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special characters in R language

Tags:

r

I have a table, which looks like this:

1β              2β     
1.0199e-01        2.2545e-01       
2.5303e-01        6.5301e-01
1.2151e+00        1.1490e+00

and so on...

I want to make a boxplot of this data. The commands I am using is this:

pdf('rtest.pdf')
 w1<-read.table("data_CMR",header=T)
 w2<-read.table("data_C",header=T)
boxplot(w1[,], w2[,], w3[,],outline=FALSE,names=c(colnames(w1),colnames(w2),colnames(w3)))
dev.off()

The problem is instead of symbol beta (β), I get two dots (..) in the output.

Any suggestions, to solve this problem.

Thank you in advance.

like image 531
Angelo Avatar asked Feb 06 '12 14:02

Angelo


2 Answers

The suggestion to use check.names will prevent the appending of "X" to the "1β" and "2β" which would otherwise occur even once the encoding is sorted out (since column names are not supposed to start with numbers. (One could also have just used the"names" argument to boxplot.)

w1<-read.table(text="1β              2β     
 1.0199e-01        2.2545e-01       
 2.5303e-01        6.5301e-01
 1.2151e+00        1.1490e+00",header=TRUE, check.names=FALSE, fileEncoding="UTF-8")
boxplot(w1)

enter image description here

like image 110
IRTFM Avatar answered Sep 22 '22 04:09

IRTFM


This also works

pdf('rtest.pdf')
w1<-read.table("data_CMR",header=T) 
w2<-read.table("data_C",header=T) 
one<-expression(paste("1", beta,sep="")) 
two <- expression(paste("2", beta,sep="")) 
boxplot(w1[,], w2[,], w3[,],outline=FALSE, names=c(one,two)) 
dev.off()
like image 37
Angelo Avatar answered Sep 22 '22 04:09

Angelo