[R] numbers on barplot

Greg Snow Greg.Snow at imail.org
Mon Jul 27 18:18:05 CEST 2009


Unless you are intentionally trying to distort your data and make the graph harder to read (you don't want to do that), it is better to put the numbers in the margin rather than at the top of the bars.  Try the following line after the barplot:

> mtext( dat$NumberOfPeople, side=1, line=1.5, at=Graph, cex=1.6 )



-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Mohsen Jafarikia
> Sent: Monday, July 27, 2009 8:02 AM
> To: R-help at stat.math.ethz.ch
> Subject: [R] numbers on barplot
> 
> Hello all,
> I have this simple barplot code:
> 
> ifn <- "id.dat"
> dat <- read.table(ifn)
> ofn <- "id.png"
> 
> bitmap(ofn, type = "png256", width = 30, height = 30, pointsize = 30,
> bg =
> "white",res=50)
> par(mar=c(5, 5, 3, 2),lwd=5)
> par(cex.main=1.6,cex.lab=1.6,cex.axis=1.6)
> 
> names(dat)<-c("NumberOfPeople","Average")
> Graph<-barplot(dat$Average)
> dev.off()
> 
> and here is the data (id.dat):
> 
> 15    0.08
>  6    0.09
>  7    0.37
> 
> I want to write down the ""NumberOfPeople" on top of each of the bars.
> Can
> anybody help me on this?
> 
> Thanks,
> Mohsen
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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