Using ggplot2
, this is easy. You have complete control over the length of all four "sides" of the errorbars. With geom_errorbar()
you set the y-errors, and geom_errobarh()
(the h is for horizontal) you set the x-errors.
#toy data
df <- data.frame(X = rnorm(4), errX = rnorm(4)*0.1, Y = rnorm(4), errY = rnorm(4)*0.2)
#load ggplot2
require(ggplot2)
#make graph
ggplot(data = df, aes(x = X, y = Y)) + geom_point() + #main graph
geom_errorbar(aes(ymin = Y-errY, ymax = Y+errY)) +
geom_errorbarh(aes(xmin = X-errX, xmax = X+errX))
You have separate control for the color of each bar, the linewidth, etc by setting parameters inside geom_errorbar()
. See the help and Google for details. For example, you can control the width of the "caps" or eliminate them entirely with the width
parameter. Compare the graph above to this one for an example of removing them:
ggplot(data = df, aes(x = X, y = Y)) + geom_point() +
geom_errorbar(aes(ymin = Y-errY, ymax = Y+errY), width = 0) +
geom_errorbarh(aes(xmin = X-errX, xmax = X+errX), height = 0)