Skip to content
Prev 174559 / 398503 Next

barplot2 x-axis

Looking at the graphic (I got it here, but it was stripped for those  
getting it via the server), the CI's don't really add much to the  
interpretation of the data. They are small enough as to be a non-issue  
at least in this example and there is too much data to make them  
useful for visually comparing the means across the bars anyway.

The values along the x axis that you are getting are the result of  
there being too many small vertical bars in the space and that the  
size of the font for the bars is too large to display all of the  
labels. The other consideration, is that the horizontal spacing of the  
bars will not be based upon their numeric value on a linear scale, but  
their physical sequence in your data. Thus, if there are sequence gaps  
in the distance measures along the x axis, those gaps will not be  
maintained when displayed, resulting in a compromised linear scale  
along the axis.

For example, consider:

x <- c(1:5, 8, 15:18)

names(x) = c(1:5, 8, 15:18)

barplot(x)


Note that there are gaps (6:7 and 9:14) where data is not present, but  
the bars (5/8 and 8/15) are nevertheless next to each other. You would  
need to insert NA's at the missing data points to maintain the proper  
bar locations along the x axis.

Here is what it should look like:

x <- c(1:5, NA, NA, 8, rep(NA, 6), 15:18)

names(x) <- c(1:5, NA, NA, 8, rep(NA, 6), 15:18)

barplot(x, cex.names = 0.75)



Contrast how barplot() handles such data by default versus plot():

x <- c(1:5, 8, 15:18)

plot(x, x, type = "h", lwd = 10)



Recognizing that there may be community standards for you in how such  
data (presumably animal or vegetative abundance data) should be  
presented, my recommendation otherwise in a vacuum would be to plot  
the data using points and leave out the CIs:

  plot(mydata.x, mydata.y, xlab = "km", ylab = "kg", main = "plot.name",
       xlim = c(0, 250), xaxt = "n", pch = 19)

  axis(1, at = seq(0, 250, 25))


or if you need bars (use type = "h" as above), if that is the  
preferred presentation format:

  plot(mydata.x, mydata.y, xlab = "km", ylab = "kg", main = "plot.name",
       xlim = c(0, 250), xaxt = "n", type = h", lwd = 5)

  axis(1, at = seq(0, 250, 25))



The bottom line is the key take away message that you are trying to  
convey, without that message being lost in too much ink.

HTH,

Marc
On Mar 22, 2009, at 4:45 PM, Mafalda Viana wrote: