Skip to content

Barchart legend position

2 messages · Spilak,Jacqueline [Edm], Deepayan Sarkar

#
On 6/22/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak at ec.gc.ca> wrote:
I can be more specific if you say what exactly you want to do
(preferably with a small reproducible example). The relevant
documentation is the part under 'key' in help(barchart). I prefer to
use 'auto.key' instead (and you haven't told us what you are using),
but most components of 'key' can be passed through 'auto.key'. Some
examples:


barchart(Titanic,
         auto.key = list(space = "right", size = 2, cex = 0.5))


barchart(Titanic,
         auto.key = list(x = 0.75, y = 0.25, size = 2))


## choose location interactively:

library(grid)

barchart(Titanic,
         page = function(n) {
             cat("Click on plot to place legend", fill = TRUE)
             ll <- grid.locator(unit = "npc")
             if (!is.null(ll))
                 draw.key(simpleKey(dimnames(Titanic)$Survived,
                                    rect = TRUE, points = FALSE),
                          vp = viewport(x = ll$x, y = ll$y),
                          draw = TRUE)
       })


-Deepayan