Skip to content
Prev 62832 / 398498 Next

axis placement with stacked barplots and the asp=1 parameter

On Fri, 2005-01-21 at 12:09 +0000, Kavithan Siva wrote:
There are a couple of options to consider here. First, note that using
the 'asp' argument forces the x and y axes to be scaled such that one
unit of measurement in each direction is the same. As you are seeing,
this impacts the look of curves and of course would be relevant to
certain plots where the horizontal and vertical measures need to be
"square".

One option is to leave the plot as is, but "move" the y axis closer to
the bars. Using your same data above:

# Draw the plot, but no axes
barplot(dataSeries, asp=1, axes= FALSE)

# Now using the 'line' argument, move the axis closer
# to the bars. Negative values move the axis to the right.
axis(2, line = -14)


Another option, which results in something closer to the barplot when
not using the 'asp' argument, is to adjust the 'width' argument to
increase the horizontal size of the bars:

# Draw the barplot and increase the width of the bars
# Do not draw the axes
barplot(dataSeries, asp=1, width = 8, axes = FALSE)

# Now draw the y axis
axis(2, at = seq(0, 12, 2))

Note however, that in this example, the vertical dimension is
"shortened", since the 'asp' argument is still trying to properly set
the aspect ratio and the larger bar width increases the range of the x
axis.


Finally(?), another option to consider is to set par(pty = "s") as an
alternative to using 'asp = 1'. This results in a square plot region,
rather than a maximal (typically rectangular) one. See ?par for more
info here. In this case:

par(pty = "s")
barplot(dataSeries)

This might result in better looking arcs for your corners.

Without having your modified barplot() function, it is hard to know
which might work best here, but hopefully this might provide some
possibilities.

HTH,

Marc Schwartz