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
I think you need
scale_fill_continuous("Your new label")
Note that you can simplify
scale_y_continuous(formatter = "percent") + ylab("Anteil in
%")
To
scale_y_continuous("Anteil in %", formatter = "percent")
HTH,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Christian Schulz
Verzonden: maandag 18 januari 2010 13:34
Aan: r help
Onderwerp: [R] ggplot2 histogramm
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.2
8,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
______________________________________________
R-help at r-project.org 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.
Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.
Hi Dennis, the BaseTheme() are some settings scale the text and title etc. , the plot should work without that. At present i'm experiment with the huge amount of possibilities and try to understand and maybe doing beginner mistakes. Thanks for the hint with scale_fill_gradient and specialized mailing list. Regards , Christian> 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 > > > ______________________________________________ > R-help at r-project.org <mailto:R-help at r-project.org> 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. > >