Scientist
Scientist

Reputation: 1359

Displaying the axes on mirror barplot in (basic) R

Sorry if the question is quite naive but I am stuck and could not find a specific answer elsewhere. I am a beginner. I cannot make the vertical axis show in the plot explained below.

barplot(-(seq(0,10,2)), width=0.6, space=1, xlim=c(-12,12), ylim=c(2,10), horiz=T, axisnames=FALSE,col="green")
barplot(seq(0,10,2),add=T, width=0.6, space=1, axes=F,horiz=T,axisnames=FALSE,col="darkred")

When I try to "include the option axis.lty=1 to draw it" (quoted from statmethods.net) I get warning saying it is "no graphical parameter". Please could anyone enlighten me in using boxplot() to solve this? Thanks in advance.

Upvotes: 1

Views: 769

Answers (1)

mt1022
mt1022

Reputation: 17299

see the manual of barplot:

axisnames logical. If TRUE, and if there are names.arg (see above), the other axis is drawn (with lty = 0) and labeled.

axis.lty the graphics parameter lty applied to the axis and tick marks of the categorical (default horizontal) axis. Note that by default the axis is suppressed.

That axis will be drawn only when the height parameter has names attributes or you supplied names.arg. When this criteria was satisfied, a blank axis line will be drawn, and you can make it visible with axis.lty = 1. See the following example (the horizontal axis overlapped the first bar because you set ylim to c(2, 10)):

barplot(
    -(seq(0,10,2)), width=0.6, space=1, names.arg = paste('h=', -(seq(0,10,2))),
    xlim=c(-12,12), ylim=c(2,10),
    horiz=T, axisnames=T,col="green", axis.lty = 1, las = 1)

barplot(seq(0,10,2),add=T, width=0.6, space=1,
        axes=F,horiz=T,axisnames=FALSE,col="darkred", axis.lty = 1)

enter image description here

Upvotes: 2

Related Questions