[R] barplot x axis
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Sun Oct 13 09:27:01 CEST 2002
The error appears to have been in R 1.5.x, not 1.6.0. The horizontal axis
was plotted with lty=0, and that was not being respected in 1.5.x. As
from 1.6.0 axis() does respect lty (and other arguments: see the NEWS
file).
BTW, please do use the R version numbers, not your own private ones!
On Sat, 12 Oct 2002 aolinto at bignet.com.br wrote:
> Dear Schwartz and Pausas,
>
> Thanks for your messages.
>
> I was referring to the axis line and its tick marks.
>
> If you write barplot(table(c(1,2,2,3,3,3,4,4,5))) in R150 and in R160 you will
> have different plots. The last one will not display the x axis line and tick
> marks, but only x axis labels, isn't it?
>
> In this case "axis(1, at = mp, labels = 1:5)" solves the problem.
>
> Best regards,
>
> Antonio Olinto
>
>
> Marc Schwartz <mschwartz at medanalytics.com>:
>
> > To the best of my knowledge, nothing in barplot() has changed recently.
> >
> > Are you referring to having column names printed below the bars or an
> > actual axis line with tick marks and labels?
> >
> > If the former (just bar labels) then:
> >
> > If your 'height' argument does not have a 'names' attribute, then no
> > names will be printed below the bars (or to the left of the bars if
> > horiz = TRUE).
> >
> > You can check this by
> >
> > > names(height)
> >
> > replacing the actual vector name that you are using for 'height'. If it
> > returns NULL, that is why you are not getting bar labels.
> >
> > You can either create a names attribute or explicitly define the column
> > names by passing a vector of names to the 'names.arg' argument to
> > barplot().
> >
> > Try this to demonstrate:
> >
> > > test <- 1:20
> > > barplot(test)
> >
> > This will draw 20 vertical bars with no bar labels.
> >
> > Now try:
> >
> > > test <- 1:20
> > > names(test) <- 1:20
> > > barplot(test)
> >
> > Now 'test' has a names attribute and you will get 20 bars labeled with
> > 1:20 under the bars.
> >
> > Alternatively, you can also do the following using names.arg:
> >
> > > test <- 1:20
> > > barplot(test, names.arg = 1:20)
> >
> > This will also result in 20 bars labeled with 1:20 under the bars.
> >
> >
> > If the latter (a lined axis with tick marks and labels) then:
> >
> > > test <- 1:20
> > > mp <- barplot(test)
> > > axis(1, at = mp, labels = 1:20)
> >
> > The second line stores the mid-points of the bars in 'mp'. The third
> > line creates an x axis ('1'), with tickmarks set at the bar mid-points
> > ('at = mp') and labels below the tickmarks of 1:20.
> >
> > Lastly, if you want a frame around the entire plot, call:
> >
> > > box()
> >
> > HTH.
> >
> > Marc Schwartz
> >
> >
>
>
>
> ---
> Mensagem enviada via webmail.bcmg.com.br
> ---
> Bignet CMG Navegando com voce !
> SITE..: http://www.bcmg.com.br
> EMAIL.: suporte at bcmg.com.br
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list