[R] barplot x axis

aolinto@bignet.com.br aolinto at bignet.com.br
Sat Oct 12 17:02:27 CEST 2002


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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list