# [R] how can I adjust the ranges of my y-axis in barplot?

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Oct 3 20:02:43 CEST 2012

```
On 03.10.2012 19:50, Yakamu Yakamu wrote:
> Hi all,
> I am making 2 barplots with 3 different bars inside with command :
>
> bar.wdHo<-barplot(wdHo.mean, names=c(""), cex.lab=1.0, cex.axis=1, cex.names=1, ylim=c(0,15), xlab="", ylab=expression(paste("Thickness (mm"^{2},")")), density=c(0,27,200), col=c("grey90","black","grey"), beside=TRUE, axis.lty=1)
>
> and the other one :
> bar.wdHo<-barplot(wdHo.mean, names=c(""), cex.lab=1.0, cex.axis=1, cex.names=1, ylim=c(0,5), xlab="", ylab=expression(paste("Thickness (mm"^{2},")")), density=c(0,27,200), col=c("grey90","black","grey"), beside=TRUE, axis.lty=1)
>

Not reproducible for us ...

> My question is :
>
> how can i adjust the y range from 0,5,10 and 15? for the first barplot and the second to be 0, 2.5 and 5 ?
> because, even though i put the lim=c(0,15) for the first one, but then it came out as 0,2,4,and so on (with even numbers) and the max is only 14.

You set the range of the whole axis by ylim, if you want to control the
tick marks, use:

ylim=c(0,15), yaxp=c(0, 15, 3)

and

ylim=c(0,5), yaxp=c(0, 5, 2)

respectively. See ?par for details.

Otherwise, omit the y axis via yaxt="n" and add it separately by a call
to axis().

Uwe Ligges

>
> because also I would like to show "comparisons" of magnitudes with the other baplots /data that I have, one with max 15 and the other with maximum 5)
>
> Any help/comments/suggestions are highly appreciated,
> cheers,
> Yakamu
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help