|
How to write values on bars using mtext?
Grouped Bar Plot counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS",xlab="Number of Gears", col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, horiz=TRUE) mtext(counts ) # But poistion is not at each bar. How can i put corresponsing values on each bars of plot? Regards |
|
Hello,
I hope this helps. p1<-barplot(counts, main="Car Distribution by Gears and VS",xlab="Number of Gears", col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, horiz=TRUE) mtext(text=counts,las=1,side=2,outer=FALSE,at=p1) A.K. ----- Original Message ----- From: Manish Gupta <[hidden email]> To: [hidden email] Cc: Sent: Friday, August 10, 2012 10:55 PM Subject: [R] How to add values on bar of grouped bar plot using mtext? How to write values on bars using mtext? Grouped Bar Plot counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car Distribution by Gears and VS",xlab="Number of Gears", col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, horiz=TRUE) mtext(counts ) # But poistion is not at each bar. How can i put corresponsing values on each bars of plot? Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-add-values-on-bar-of-grouped-bar-plot-using-mtext-tp4640015.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Manish Gupta
On Aug 10, 2012, at 7:55 PM, Manish Gupta wrote: > How to write values on bars using mtext? > > Grouped Bar Plot > counts <- table(mtcars$vs, mtcars$gear) barplot(counts, main="Car > Distribution by Gears and VS",xlab="Number of Gears", > col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, > horiz=TRUE) > > mtext(counts ) # But poistion is not at each bar. > > How can i put corresponsing values on each bars of plot? > Please do not crosspost to SO and rhelp. Please do read the Posting Guide. > > -- > > Sent from the R help mailing list archive at Nabble.com. > -- David Winsemius, MD Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
This post has NOT been accepted by the mailing list yet.
I think mtext write on margin but i need on values on bars. I found text is more useful. How can i use text to write on it.
Regards |
|
This post has NOT been accepted by the mailing list yet.
Try this:
counts <- table(mtcars$vs, mtcars$gear) p1<-barplot(counts, main="Car Distribution by Gears and VS",xlab="Number of Gears", col=c("darkblue","red"),legend = rownames(counts), beside=TRUE, horiz=TRUE,xlim=c(0,14)) text(counts,p1,formatC(counts,digits=2),pos=4) A.K. |
| Powered by Nabble | Edit this page |
