[S] Re: x axis limits on barchart

Douglas Bates (bates@stat.wisc.edu)
26 May 1998 09:48:33 -0500


Douglas Bates <bates@stat.wisc.edu> writes:

> I was using barchart today to prepare some graphs for a paper when I
> noticed that the size of the bars was misleading because the bars did
> not start at zero. The data I was plotting looked like
>
> tiger <- data.frame( proportion = c(9.5, 8.8, 3.1, 1.7, 1.2, 0.1),
> activity = c("Sleeping", "Pacing", "Feeding", "Grooming",
> "Vocalizing", "Hunting"))
> barchart( activity ~ proportion, data = tiger )

I apologize for replying to my own query but Bill Venables was kind
enough to remind me that I had already solved this problem in another
context. The solution is to specify a "scales" argument to the
barchart call and within the x-axis scales list use "axs", not "xaxs"
as I was trying to do.

S> tiger <- data.frame( proportion = c(9.5, 8.8, 3.1, 1.7, 1.2, 0.1),activity
+ = c("Sleeping", "Pacing", "Feeding", "Grooming", "Vocalizing", "Hunting"))
S> tiger$activity <- factor(tiger$activity, levels = unique(tiger$activity))
S> barchart( activity ~ proportion, data = tiger,
+ scales = list(x = list(axs = "i")), xlim = c(0,10))

That produces a bar chart with the "Sleeping" bar on the bottom and
the "Hunting" bar on the top. If, like me, you prefer to reverse them
so it looks like a Pareto chart, you can use

S> tiger$activity <- ordered(tiger$activity, levels = rev(levels(tiger$activity)))
S> barchart( activity ~ proportion, data = tiger,
+ scales = list(x = list(axs = "i")), xlim = c(0,10))
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news