[R] tick marks and barchart

Stefán Hrafn Jónsson stefan at rannsoknir.is
Thu Oct 16 17:03:59 CEST 2003


Dear R community.

I have two problems with figures. First deals with short vector on the
x-axis and the second with two-panel barchart.
1) For demonstration I create the following pseudo data for three years,
2001:2003. The indicated plot looks fine except for the number of tick
marks on the x-axis. I get seq(2001,2003,0.5). I want three and only three
tick marks to indicate we have measure once a year not two times each
year. (Having year 2001.5 is not that nice anyway). I tried
as.factor(2001:2003) but this did not do what I want. I have considered
having no labels and plot the year with text(y=-b,x=(2001,2002,2003),
(2001:2003)  ) -b being some value less than 0. A simpler version is
preferred.
2) For the second problem I want to use the same data but create a
barchart with two bars (Group A and group B) for 2001, same two groups for
2002 and same two for 2003. Group A would have blue bars and Group B  red
bars.
Would I use barchart() or panel.barchart()?  Looking in help(barchart) I
find that I need to define a formula.  What would the x, y and g1 be in my
case?

All help highly appreciated


Thanks,
Stefan


demo1 <- matrix(nrow=3, ncol =2, log(c(7,3,2,4,5,6))/log(7) , dimnames
                               =list(as.character(2001:2003),
			        c("Group A","Group B")) )

windows()
par(lab=c(3, 6,7) ,las=1  )

plot(x=(2001:2003), y=demo1[,1]*100,type = "l",
    lwd=3,ylim=c(0,100), xlab = "" , ylab="%")
lines(x=(2001:2003), y=demo1[,2]*100,
    lwd=3, xlab = "Year" )




More information about the R-help mailing list