[R] barplot x axis
Marc Schwartz
mschwartz at medanalytics.com
Sat Oct 12 04:44:25 CEST 2002
> -----Original Message-----
> Hi,
>
> I'm running r160 under Windows 98SE and I noticed that barplots are
> different in this version. "X" axis line is not drawn any more. How
can I
> make it visible again?
>
> Thanks,
>
> Antonio Olinto
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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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