[R] Barchart legend position
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Jun 22 23:25:09 CEST 2007
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
More information about the R-help
mailing list