Re: [R] Barchart legend position

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri, 22 Jun 2007 14:25:09 -0700

On 6/22/07, Spilak,Jacqueline [Edm] <Jacqueline.Spilak_at_ec.gc.ca> wrote:
> I am using barchart to make charts for some data with a lot more
> functions and labels and such in the command.
>
> barchart(Freq ~ factor(HH), data = dataset1, group= year)
>
> So I have my data grouped by year and I get a legend at the top of
> graph, which is great cause I need the legend for the different years
> but it is a weird spot. So how can I manipulate the legend, ie. Move
> it, shrink it, do anything with it. I have searched the help archives
> and found nothing, and I have looked up the legend section in ?barchart
> but that has not helped or I am doing something wrong. Any help is
> greatly appreciated.

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



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 22 Jun 2007 - 21:42:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 22 Jun 2007 - 22:32:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.