[R] How to add values on bar of groouped bar plot using mtext?
Uwe Ligges
ligges at statistik.tu-dortmund.de
Sat Aug 11 16:27:15 CEST 2012
On 11.08.2012 04:55, 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?
Look at the output of barplot, it returns the locations:
bp <- barplot(counts, main = "Car Distribution by Gears and VS",
xlab = "Number of Gears", col = c("darkblue", "red"),
legend = rownames(counts), beside = TRUE, horiz = TRUE)
bp
mtext(side = 2, at = bp, text = counts)
Uwe Ligges
>
> Regards
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-add-values-on-bar-of-groouped-bar-plot-using-mtext-tp4640014.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list