Hi:
I have to admit, there are several things about your call I don't
understand. First of all,
you're really constructing bar charts by group, not histograms.
Secondly, you don't want
legend.text, but legend.title; unfortunately, that doesn't work (for
reasons I don't understand),
so I put in a workaround with scale_fill_gradient(). Thirdly, I
couldn't find a function called
BaseTheme() in ggplot2; is this in package ggExtra?
I got some errors when running your code. The first one had to do with
BaseTheme (not found).
When I got rid of that, there was the following (in my modified code):
p + geom_bar(aes(y= ..count.. /
sum(..count..),fill=..count../sum(..count..)*100)) +
+ scale_y_continuous("Anteil in %", formatter = "percent") +
+ facet_wrap(~ group) + xlab("Attribute") +
+ opts(title="Title")
last_plot() + opts(legend.title = "Antiel in Prozent")
Error in el(...) : unused argument(s) (x = 0, y = 0.5)
(It happened in yours, too.) I got the following to work; I think it's
what you want, but let
me know if I'm off.
p + geom_bar(aes(y= ..count.. /
sum(..count..),fill=..count../sum(..count..)*100)) +
scale_y_continuous("Anteil in %", formatter = "percent") +
scale_fill_gradient("Antiel in Prozent", limits = c(0, 50)) +
facet_wrap(~ group) + xlab("Attribute") +
opts(title="Title")
HTH,
Dennis
PS: Questions about ggplot2 are better directed to its mailing list:
ggplot2 at googlegroups.com <mailto:ggplot2 at googlegroups.com>
On Mon, Jan 18, 2010 at 4:34 AM, Christian Schulz <chschulz at email.de
<mailto:chschulz at email.de>> wrote:
Hi,
i get no success change the title of the "fill" (colour) legend
and the defintion of "levels". Have anybody a hint how i can do this.
df <-
data.frame(variable=sample(c("A","B","C"),1000,replace=T,prob=c(0.22,0.28,0.5)),group=gl(2,500))
p <- ggplot(df, aes(x = variable))
p + geom_histogram(aes(y= ..count.. /
sum(..count..),fill=..count../sum(..count..)*100)) +
scale_y_continuous(formatter = "percent") + facet_wrap(~group) +
ylab("Anteil in %") + xlab("Attribute") +
opts(title="Title",legend.text="Anteil in Prozent") +
BaseTheme(base_size=12)
many thanks,
Christian