[R] changing number of axis

Deepayan Sarkar deepayan.sarkar at gmail.com
Wed Sep 30 07:59:30 CEST 2009


On Wed, Sep 16, 2009 at 2:02 PM, Dan Kortschak
<dan.kortschak at adelaide.edu.au> wrote:
> Hi, I trying to produce a bar chart describing hits to specific bins by
> chromosome for a large data set (I am asking here because
> experimentation with options is precluded due to this - generating the
> figure takes about an hour):
>
> barchart(hits~bin|chromosome, data=hits, horizontal=FALSE, origin=0,
> lab=c(3,10), layout=c(1,5,5), strip=strip.custom(style=3, bg="grey90",
> par.strip.text=list(cex=0.5)), as.table=TRUE);
>
> I have about 2500 bins for the largest factor and barchart is drawing
> tick labels for a substantial proportion of these (how many, I can't see
> since due to the density of the labels).

Probably all 2500 of them.

> My question is how I can get a sane number of labels along the x axis
> (about 5-10 would be good). I suspect that 'scales' might be the way to
> go, but I can't see an obvious option to do this.

Basically, barchart has to be convinced that the limits are numeric.
There are various ways to do that; the simplest is to provide a
numeric 'xlim', e.g.,

df <- data.frame(y = runif(100), x = gl(100, 1))
barchart(y ~ x, df, origin = 0)
barchart(y ~ x, df, origin = 0, xlim = c(0, 101))

However, you should also rethink the use of barchart for a 2500-level
factor; at a minimum, consider something like

xyplot(y ~ as.numeric(x), df, type = "h")

-Deepayan




More information about the R-help mailing list