[R] Barplot legend position

Peter Danenberg pcd at wikitex.org
Wed Apr 11 03:38:34 CEST 2007

> However, the legend does not reproduce the color/shading used in the
> original barplot, are those available somehow?

     Actually,  Ingmar, there's a more elegant way to recre-
ate the original colors; to expand on your example:

     data <- 1:10
     rows <- 2
     cols <- 5
     labels <- c('left', 'right')
     position <- 'topleft'
     colors <- gray.colors(rows)
     inset <- c(0.1, 0.1)

     height = matrix(data, rows, cols)
     barplot(height, beside=T)
     legend(position, labels, fill=colors, inset=inset)

     The key is the `gray.colors()' palette; and `inset'  is
for beautification.

Best, Peter

More information about the R-help mailing list