Beginner help

11 views
Skip to first unread message

bioinformed

unread,
Jan 22, 2010, 9:42:21 AM1/22/10
to ggplot2
Hi all,

I'm just starting to learn how to use ggplot2 and am extremely
impressed with both the software and the community that has developed
around it. My plots are looking better than ever and many of my
colleagues have taken note. Kudos to all involved!

My question is how to merge these two plots into a single one:

ggplot(data) + eas(x='signal') + geom_density()

ggplot(data) + eas(x='signal',color='factor(bin)') + geom_density()

I can get a beautiful density plot of my signal and another for the
density by "bin". What I'm having trouble with is combining both
plots into a single one.

Am I missing something obvious? Any help will be greatly appreciated.

Thanks,
-Kevin

ONKELINX, Thierry

unread,
Jan 22, 2010, 9:47:10 AM1/22/10
to bioinformed, ggplot2
Kevin,

Something like this?

ggplot(data, aes(x= signal)) + geom_density() + geom_density(aes(colour
= bin))

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....@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: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] Namens
bioinformed
Verzonden: vrijdag 22 januari 2010 15:42
Aan: ggplot2
Onderwerp: Beginner help

Hi all,

Thanks,
-Kevin

--
You received this message because you are subscribed to the ggplot2
mailing list.
To post to this group, send email to ggp...@googlegroups.com To
unsubscribe from this group, send email to
ggplot2+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ggplot2

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.

Kevin Jacobs <jacobs@bioinformed.com>

unread,
Jan 22, 2010, 10:08:20 AM1/22/10
to ONKELINX, Thierry, ggplot2
On Fri, Jan 22, 2010 at 9:47 AM, ONKELINX, Thierry <Thierry....@inbo.be> wrote:
Kevin,

Something like this?

ggplot(data, aes(x= signal)) + geom_density() + geom_density(aes(colour
= bin))


Exactly like that.  Many thanks!  Is here a way to add an entry to the legend to indicate that one of the series is the marginal density?

-Kevin

ONKELINX, Thierry

unread,
Jan 22, 2010, 10:15:35 AM1/22/10
to jac...@bioinformed.com, ggplot2
I not aware of a nice way to do that. But here is a quick hack. This will give you an extra 'bin' class with the marginal data.
 
tmp <- data
tmp$bin <- "Marginal"
data <- rbind(data, bin)
ggplot(data, aes(x = signal, colour = bin)) + geom_density()
 

----------------------------------------------------------------------------


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....@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
 

 


Van: Kevin Jacobs <jac...@bioinformed.com> [mailto:bioin...@gmail.com]
Verzonden: vrijdag 22 januari 2010 16:08
Aan: ONKELINX, Thierry
CC: ggplot2
Onderwerp: Re: Beginner help

hadley wickham

unread,
Jan 22, 2010, 10:19:26 AM1/22/10
to ONKELINX, Thierry, jac...@bioinformed.com, ggplot2
The easiest way is to do this:

ggplot(data, aes(x= signal)) + 
  geom_density(aes(colour = "margin")) + 
  geom_density(aes(colour = bin))
Reply all
Reply to author
Forward
0 new messages