[R] Advice on using barplot

Andrew Perrin andrew_perrin at unc.edu
Thu Feb 14 17:53:36 CET 2002


Greetings-

I'm venturing into a new (for me) area of using R: some presentation
graphics based on R data.

I'd like to compare two distributions of ordinal variables in relatively
small (N=203 and 207) subsets of an R dataset.  I can get a reasonably
good picture of the distributions' differences with:

x11()
plot(table(hcd.df$auth.sum[hcd.df$datecat==1]), type='l',xlim=c(-8,7),
ylim=c(0,59))
par(new=TRUE)
plot(table(hcd.df$auth.sum[hcd.df$datecat==2]), type='l',
col='red',xlim=c(-8,7), ylim=c(0,59))

but the line style is awkward and possibly even misleading when the values
are ordinal. What I'd like to use is a barplot, such that the
distributions are interspersed by value; that is, the furthest left bar
represents auth.sum==-8 where datecat==1, then immediately next to it is
auth.sum==-8 where datecat==2, then a small amount of space, then the -7
bars, etc.  (I may not be doing the best job describing this, but it's a
commonly-seen graph type; see
http://www.parentingbookmark.com/media/bar%20graph.jpg for an example
[thanks to images.google.com for finding it]).

The closest I've come is to use:
barplot(table(hcd.df$auth.valence, hcd.df$datecat), beside=TRUE)

which plots the two *distributions* side by side (all the datecat==1 then
all the datecat==2).

Any advice?

Thanks.

----------------------------------------------------------------------
Andrew J Perrin - andrew_perrin at unc.edu - http://www.unc.edu/~aperrin
 Assistant Professor of Sociology, U of North Carolina, Chapel Hill
      269 Hamilton Hall, CB#3210, Chapel Hill, NC 27599-3210 USA


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list