An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090202/8db31d3b/attachment-0001.pl>
Broke ggplot...
8 messages · Jason Rupert, Hadley Wickham
On Mon, Feb 2, 2009 at 5:41 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
It appears I broke ggplot in my script, but that maybe it is because the caffeine has worn off or maybe it is late in the day. I thought I was beginning to understand ggplot, but I have encountered a silly little issue. For some reason the following does not produce a histogram with fill due to the Person's characteristics: (Note that VADeaths_flat_df$Data works fine...) VADeaths_df<-data.frame(VADeaths)
...
You can do this a bit more easily with:
VADeaths_flat_df <- melt(VADeaths)
names(VADeaths_flat_df) <- c("Age", "Person", "Data")
bin_size<-15.0 ggplot(VADeaths_flat_df, aes(x = factor(Data), fill = factor(Person))) + geom_bar(position=position_dodge(width =(20)), binwidth=20) # or ggplot(VADeaths_flat_df, aes(x=factor(Data))) + geom_histogram(binwidth=20)
Those plots look fine to me (well they're what I'd expect from the definition), but I'd think you'd want ggplot(VADeaths_flat_df, aes(Data, fill = Person)) + geom_histogram(binwidth=20) or maybe ggplot(VADeaths_flat_df, aes(Person, weight = Data)) + geom_bar() ggplot(VADeaths_flat_df, aes(Person, weight = Data, fill = Age)) + geom_bar() Hadley
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090202/c5317b9f/attachment-0001.pl>
Hi Jason,
I can't see anyway to do this completely within in ggplot. And it's
not easy to do the data processing yourself. Here's one attempt that
almost works:
counts <- ddply(VADeaths_flat_df, .(round_any(Data, 20), Person), nrow)
names(counts) <- c("bin", "person", "n")
qplot(bin, n, data = counts, fill = person, geom="bar", stat
="identity", position="dodge")
Or maybe:
counts <- ddply(VADeaths_flat_df, .(cut(Data,
breaks=fullseq(range(Data), 20)), Person), nrow)
names(counts) <- c("bin", "person", "n")
qplot(person, n, data = counts, fill = person, geom="bar", stat
="identity", width = 0.9) +
facet_grid(. ~ bin) +
opts(axis.text.x = theme_text(angle = 45, hjust = 1, colour = "grey60"))
Hadley
On Mon, Feb 2, 2009 at 8:32 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
Using the following code to have a little separation between the individual
bins:
VADeaths_flat_df = stack(as.data.frame(VADeaths))
names(VADeaths_flat_df) = c('Data','Person')
ggplot(VADeaths_flat_df, aes(Data, fill = Person)) +
geom_bar(position=position_dodge(width =(15)), binwidth=20)
The result shows the bars overlapping.
Is there any way to fix it by reducing the bar sizes?
Thanks again.
--- On Mon, 2/2/09, hadley wickham <h.wickham at gmail.com> wrote:
From: hadley wickham <h.wickham at gmail.com>
Subject: Re: [R] Broke ggplot...
To: jasonkrupert at yahoo.com
Cc: R-help at r-project.org
Date: Monday, February 2, 2009, 5:49 PM
On Mon, Feb 2, 2009 at 5:41 PM, Jason
Rupert <jasonkrupert at yahoo.com>
wrote:
It appears I broke ggplot in my script, but that maybe it is because the
caffeine has worn off or maybe it is late in the day. I thought I was beginning to understand ggplot, but I have encountered a silly little issue.
For some reason the following does not produce a histogram with fill due
to the Person's characteristics:
(Note that VADeaths_flat_df$Data works fine...) VADeaths_df<-data.frame(VADeaths)
...
You can do this a bit more easily with:
VADeaths_flat_df <- melt(VADeaths)
names(VADeaths_flat_df) <- c("Age", "Person",
"Data")
bin_size<-15.0 ggplot(VADeaths_flat_df, aes(x = factor(Data), fill = factor(Person))) +
geom_bar(position=position_dodge(width =(20)), binwidth=20)
# or ggplot(VADeaths_flat_df, aes(x=factor(Data)))
+ geom_histogram(binwidth=20) Those plots look fine to me (well they're what I'd expect from the definition), but I'd think you'd want ggplot(VADeaths_flat_df, aes(Data, fill = Person)) + geom_histogram(binwidth=20) or maybe ggplot(VADeaths_flat_df, aes(Person, weight = Data)) + geom_bar() ggplot(VADeaths_flat_df, aes(Person, weight = Data, fill = Age)) + geom_bar() Hadley -- http://had.co.nz/
1 day later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090204/a0cf162e/attachment-0001.pl>
On Wed, Feb 4, 2009 at 9:26 AM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
Hadley, Thank you again for your suggestion. I am going with the second solution. It appears to have a consistent bar width and helps to illustrate when data is not present within a certain bin. One other silly question - how in the world do I get the x-axis label to "not" show up? I want the x-label, but not the x-axis to appear, e.g. for the example below the not to see the "Rural Feamale", "Rural Male", ... that are on the lower x-axis?
The easiest way is + xlab("") or + xlab(NULL)
Hadley
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090204/5d8a9083/attachment-0001.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090204/b236fe42/attachment-0001.pl>