On Mar 22, 2009, at 2:31 PM, Mafalda Viana wrote:
Dear R users,
I am trying to build a barplot2 graph however I can't find a way of
defining
the scale for the x-axis.
I would like to show in my x-axis only the numbers 0, 25, 50, 75 etc. (so
far R is giving me a random scale hard to interpret and it doens't look
nice...). Could anyone advise me on how to do this please, it would be a
great help! Thank you.
Below I show the code I have been using for my plots.
my.plot<- barplot2(mydata.y, names.arg=mydata.x, width=1,
xlab="km", ylab="kg", main="plot.name",
plot.ci=TRUE, ci.l=data.lci,ci.u=data.uci, ci.col = "red", font=40,
font.lab=60, xlim=c(0,250), xpd=FALSE)
It is not entirely clear what you are doing here an we cannot reproduce it
lacking your data.
Your x (horizontal) axis will have one tick mark below each bar, using the
labels that you have indicated with mydata.x. Based upon your code, the x
axis values would appear to be measures of distance.
Your y (vertical) axis would appear to be a measure of weight, perhaps
being some descriptive statistic (eg. mean) for weight at each distance.
It is unclear what you want to do with the x axis in lieu of the default
values. Modifying the tick marks on the y axis would seem to make more sense
here.
In general, with any R graphic, you would use the arguments 'xaxt = "n"'
and/or 'yaxt = "n"' to disable the default drawing of the x and y axes,
respectively. You would then call the axis() function passing the specific
locations and values of the tick marks that you wish to draw. See ?par and
?axis for more information on these.
BTW if you are not plotting counts or proportions/percentages, then a
barplot is not the best approach for the display of summarized continuous
data. I would use a point plot with error bars/confidence intervals. See the
errbar() function in the Hmisc package or the plotCI() or plotmeans()
functions in gplots. You could also create something manually by using
plot() and then either segments() or arrows() for the CIs.
HTH,
Marc Schwartz