Quantcast

How to write values on bars of bar plot?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

How to write values on bars of bar plot?

Manish Gupta
This post has NOT been accepted by the mailing list yet.
Hi,

This is with ref to my previous question. I am writing here input data and my real pblm.

Input File:

A 15.918 19
B 8.822 7
C 0.619 0
D 0.06 0
E 0.479 1
F 2.913 3
G 2.456 2
H 0.927 1
I 1.121 0
J 0.255 0
K 0 1
L 0.549 1
M 0.095 0


require(grDevices)
pie(rep(1, 24), col = rainbow(24), radius = 0.9)
disease_data<-read.table("Input.txt" , sep="\t",header=FALSE,quote="\"", check.names=FALSE)
mp<-barplot(t(disease_data[,2:3]),  beside=TRUE, col=c(rgb(.537, .769, .933),rgb(.059, .412, .659)), width = 1, horiz=TRUE,cex.names=.9, border ="white",las=1, cex.axis= 1, cex.lab=1.2,axes = FALSE)
abline(v = 0, lwd = 1, col = 1)
text(mp, t(disease_data[,2:3]), xpd = TRUE , pos=3)



I cannot write on bar even if i used text with different parameters. I got answers for mtext in my previous thread this time i need to write on bars not on margin. Pls help me in this matter.

Regards
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to write values on bars of bar plot?

Manish Gupta
This post has NOT been accepted by the mailing list yet.
Just a reminder,  pls help me.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How to write values on bars of bar plot?

arun kirshna
This post has NOT been accepted by the mailing list yet.
In reply to this post by Manish Gupta
Hello,
Try this:
dat1<-read.table(text="
A 15.918 19
B 8.822 7
C 0.619 0
D 0.06 0
E 0.479 1
F 2.913 3
G 2.456 2
H 0.927 1
I 1.121 0
J 0.255 0
K 0 1
L 0.549 1
M 0.095 0
",sep="",header=FALSE)
dat2<-as.matrix(dat1[,2:3])
dat2<-t(dat2)
mp<-barplot(dat2,  beside=TRUE, col=c(rgb(.537, .769, .933),rgb(.059, .412, .659)), width = 1, horiz=TRUE,cex.names=.9, border ="white",las=1, cex.axis= 1, cex.lab=1.2,xlim=c(0,21),names.arg=LETTERS[1:13])
abline(v = 0, lwd = 1, col = 1)
text(dat2,mp,signif(dat2,2),pos=4,cex=0.8)

A.K.
Loading...