An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090205/cb9f26f2/attachment-0001.pl>
A way to "lock down" the order of bars for ggplot "dodged" histogram
5 messages · Jason Rupert, ONKELINX, Thierry, Hadley Wickham
Dear Jason,
Convert Person to a factor with the levels in the order that you want.
Group_df$Person <- factor(Group_df$Person, levels = c("Them", "You", "Me"))
HTH,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and 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 Jason Rupert
Verzonden: donderdag 5 februari 2009 17:09
Aan: R-help at r-project.org
CC: ggplot2 at googlegroups.com
Onderwerp: [R] A way to "lock down" the order of bars for ggplot "dodged"histogram
It appears that ggplot?reorder?the?data for a "dodged"?histogram?based on whether or not a specific variable has a value in the first bin.
?
I would like to be able to absolutely force the order of the variables in the bin.? For example, say I have three variables Me, You, and Them.
?
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)), Person), nrow)
names(counts) <- c("Bin", "Person", "Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar", stat="identity", width = 0.9, xlab="Person") +? facet_grid(. ~ Bin)
?
However, I absolutely?must have?the bar order?be Them, You, Me.?? Is there a to fix the order of the bars so that they are always in the Them, You, Me order?
?
Thank you again for any feedback you can provide.?
?
?
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090205/09790476/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090206/50ca9107/attachment-0001.pl>
Yes, I think it is. I'll add it to my to do list. Hadley On Fri, Feb 6, 2009 at 3:30 AM, ONKELINX, Thierry
<Thierry.ONKELINX at inbo.be> wrote:
Hmm, I had not tested my solution. But that used to work. But I'm getting the same result as you do. So maybe this is a bug in ggplot2. Is it, Hadley? Thierry ---------------------------------------------------------------------------- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and 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
________________________________
Van: Jason Rupert [mailto:jasonkrupert at yahoo.com]
Verzonden: donderdag 5 februari 2009 17:44
Aan: R-help at r-project.org; ONKELINX, Thierry
CC: ggplot2 at googlegroups.com
Onderwerp: RE: [R] A way to "lock down" the order of bars for ggplot
"dodged"histogram
Thierry,
Thank you for such a quick response.
I changed the code, but I seem to get the same response. Ugh. Maybe I am
missing a step. Thank you again for any feedback.
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
Group_df$Person <- factor(Group_df$Person, levels = c("Them", "You", "Me"))
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)),
Person), nrow)
names(counts) <- c("Bin", "Person", "Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar",
stat="identity", width = 0.9, xlab="Person") + facet_grid(. ~ Bin)
--- On Thu, 2/5/09, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be> wrote:
From: ONKELINX, Thierry <Thierry.ONKELINX at inbo.be>
Subject: RE: [R] A way to "lock down" the order of bars for ggplot
"dodged"histogram
To: jasonkrupert at yahoo.com, R-help at r-project.org
Cc: ggplot2 at googlegroups.com
Date: Thursday, February 5, 2009, 10:17 AM
Dear Jason,
Convert Person to a factor with the levels in the order that you want.
Group_df$Person <- factor(Group_df$Person, levels = c("Them",
"You", "Me"))
HTH,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology
and 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
Jason Rupert
Verzonden: donderdag 5 februari 2009 17:09
Aan: R-help at r-project.org
CC: ggplot2 at googlegroups.com
Onderwerp: [R] A way to "lock down" the order of bars for ggplot
"dodged"histogram
It appears that ggplot reorder the data for a
"dodged" histogram based on whether or not a specific variable has a
value in the first bin.
I would like to be able to absolutely force the order of the variables in
the
bin. For example, say I have three variables Me, You, and Them.
Me_df<-data.frame(Data = c(1:15), Person = "Me")
You_df<-data.frame(Data = c(10:20), Person = "You")
Them_df<-data.frame(Data = c(15:25), Person = "Them")
Group_df_tmp<-rbind(Me_df,You_df)
Group_df<-rbind(Group_df_tmp,Them_df)
counts <- ddply(Group_df, .(cut(Data, breaks=fullseq(range(Data), 5)),
Person), nrow)
names(counts) <- c("Bin", "Person",
"Frequency")
qplot(Person, Frequency, data = counts, fill = Person, geom="bar",
stat="identity", width = 0.9, xlab="Person") +
facet_grid(. ~ Bin)
However, I absolutely must have the bar order be Them, You, Me. Is there
a to fix the order of the bars so that they are always in the Them, You, Me
order?
Thank you again for any feedback you can provide.
[[alternative HTML version deleted]]
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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the ggplot2 mailing
list.
To post to this group, send email to ggplot2 at googlegroups.com
To unsubscribe from this group, send email to
ggplot2+unsubscribe at googlegroups.com
For more options, visit this group at
http://groups.google.com/group/ggplot2
-~----------~----~----~----~------~----~------~--~---
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.