[R] X-Axis Problem with Multhist Plot
Jim Lemon
jim at bitwrit.com.au
Mon May 26 12:22:46 CEST 2008
Edward Wijaya wrote:
> I am creating a side-by-side histogram using "multhist" of PLOTRIX.
> However, I can't seem to control the X-axis.
>
> It yields the following X points in the axis:
> 1 3 5 7 9 13 17 21 25 29 33
>
> with uneven spacing between x-ticks (see attached file).
>
The axis labels are unevenly spaced, but the "ticks" (which aren't
visible) are evenly spaced at each odd number from 1 to 35. This is a
feature of R's intelligent axis labeling, not multhist.
> Especially I want to create a bar for every x-axis (1,2,3,4...36),
> now not every x-axis has a bar.
>
> Is there a way to alter my following code
> so that the x axis is evenly distributed:
>
> require(plotrix)
> dat <- read.table(file="GDS1096.modelout", head = FALSE )
>
> l <- list(dat$V2,dat$V3)
> multhist(l, ylab = "Frequency", beside = TRUE,
> freq = TRUE, col = c("blue","red"),
> xlab = "Nof Component",
> xlim = c(0,max(dat$V3)+25),
> ylim = c(0,10000))
> legend(30, 8000, c("AIC", "BIC"), fill=c("blue", "red"))
>
I can almost certainly do what you want, if not with multhist, then with
barp. Let's see, I'll have to fake the data...
fakeprobs=c(0.15,0.12,0.1,0.08,0.06,0.05,0.041,0.032,0.024,0.018,
0.013,0.009,0.007,0.005,0.004,0.003,0.0025,0.0022,0.002,0.0019,
0.0018,0.0017,0.0016,0.0015,0.0014,0.0013,0.0012,0.0011,0.001,0.0009,
0.0007,0.0005,0.0004,0.0003,0.0002)
fakeAICncomp<-sample(1:35,25000,TRUE,prob=fakeprobs)
fakeBICncomp<-sample(1:35,25000,TRUE,prob=fakeprobs)
AICcount<-hist(rbind(fakeAICncomp),plot=FALSE,breaks=1:35)$counts
BICcount<-hist(rbind(fakeBICncomp),plot=FALSE,breaks=1:35)$counts
# hmmm, tried this with multhist, can't get rid of the X axis
# so we'll have to do it with barp
barp(rbind(AICcount,BICcount),staxx=TRUE,col=c("blue","red"))
That should get you most of the way...
Jim
More information about the R-help
mailing list