Skip to content
Prev 166159 / 398502 Next

Bar Plot with Connected Points on 1 Y-Axis

on 01/06/2009 09:07 PM jimdare wrote:
One key point to note is that barplot() returns the bar midpoints. This
is noted in the help for barplot(). The bars are not centered on integer
axis values, so you need the returned values to place additional
annotation in the proper location relative to the bars.

The other thing is to set the range of the y axis using the maximum
value in Catch, plus some fudge, so that the plot covers both sets of
data and has enough room for the additional points.

Thus, presuming that your data is in a data frame called 'DF':

mp <- barplot(DF$TACC, space = 0, names.arg = DF$Year,
              ylim = c(0, 13000))

# Now use lines() to add Catch
lines(mp, DF$Catch, type = "b", pch = 19)

See ?barplot, ?lines and ?points for more information.

HTH,

Marc Schwartz