[R] how to include bar values in a barplot?

Greg Snow Greg.Snow at intermountainmail.org
Fri Aug 10 17:30:42 CEST 2007

Welcome to the world of R.

I'm glad that you found the discussion enlightening, now that you have
thought about things a bit, here is some code to try out that shows some
of the alternatives to the original plots you provided (which is best
depends on your audience and what your main question of interest is
(which comparisons are most important):

tmp <- c(34,22,77)

tmp2 <- barplot(tmp, names=LETTERS[1:3])

# put numbers at bottom of bars
axis(1, at=tmp2, labels=as.character(tmp), tick=FALSE, line = -1)

# put numbers at top of plot
axis(3, at=tmp2, labels=as.character(tmp), tick=FALSE)

# horizontal boxplot

op <- par(mar=c(5,6,4,6)+0.1)
tmp2 <- barplot(tmp, names=LETTERS[1:3], horiz=TRUE)

# put numbers on the right
axis(4, at=tmp2, labels=as.character(tmp), tick=FALSE, las=1)


# the dotplot
dotchart2(tmp, labels=LETTERS[1:3], auxdata=tmp, xlim=range(0,tmp))

# alternatives to stacked bars

tmp1 <- c(8, 22, 60, 10,  10, 21, 59, 10)
tmp2 <- factor(rep(c('A','B'), each=4))
tmp3 <- factor(rep(1:4, 2))

dotchart2(tmp1, groups=tmp2, labels=tmp3, xlim=range(0,tmp1))
dotchart2(tmp1, groups=tmp3, labels=tmp2, xlim=range(0,tmp1))

tmp <- data.frame( tmp1=tmp1, tmp2=tmp2, tmp3=tmp3 )

dotplot( tmp2~tmp1, data=tmp, groups=tmp3, pch=levels(tmp3),
	scales=list(x=list(limits=range(0,tmp1))) )
dotplot( tmp3~tmp1, data=tmp, groups=tmp2, pch=levels(tmp2),
	xlim=range(0,tmp1) )

Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at intermountainmail.org
(801) 408-8111

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Donatas G.
> Sent: Friday, August 10, 2007 2:15 AM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] how to include bar values in a barplot?
> Quoting Greg Snow <Greg.Snow at intermountainmail.org>:
> > My original intent was to get the original posters out of 
> the mode of 
> > thinking they want to match what the spreadsheet does and into 
> > thinking about what message they are trying to get across.  To get 
> > them (and possibly others) thinking I made the statements a 
> bit more 
> > bold than my actual position (I did include a couple of qualifiers).
> As an original poster (and a brand new user of R), I would 
> like to comment on the educational experience I have just received. ;)
> The discussion was interesting and enlightening, and gives 
> some good ideas about the ways (tables, graphs, graphs with 
> numbers etc.) to get the data accross to the ones one is 
> presenting to. I see some of you guys do feel quite strongly 
> about it, which is fine for me. I do not. I usually care for 
> barplot aesthetics and informativeness more than for visual 
> simplicity. That may change in time :)
> I see R graphical capabilities are huge but hard to access at 
> times - that is when spreadsheet seems preferrable. For 
> example, as a user of Linux I still cannot figure out why the 
> fonts (and graphics in general) look much more ugly on R in 
> Linux than they do in R on Windows - no smoothing, sub-pixell 
> hinting, anything like that. That is what my next free time 
> homework on R will be about
> :)
> Sincerely
> Donatas Glodenis
> PhD candidate
> Department of Sociology of the Faculty of Philosophy Vilnius 
> University Lithuania
> ______________________________________________
> R-help at stat.math.ethz.ch 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