I'm learning ggplot and am a little confused. Sometimes discrete scales work
like I'd expect, and sometimes they don't.  For example...

This works exactly like one would expect:

df<-data.frame(names=c("Bob","Mary","Joe","Bob","Bob"))
ggplot(df,aes(names))+geom_histogram()

But this yields an error:

ggplot(df,aes(names))+geom_histogram()+xlim("Bob")
Error in data.frame(count = as.numeric(tapply(weight, bins, sum, na.rm =
TRUE))$
  arguments imply differing number of rows: 0, 1

...as does this:

ggplot(df,aes(names))+geom_histogram()+xlim("Bob","Mary")

... but this works fine:

ggplot(df,aes(names))+geom_histogram()+xlim("Bob","Mary","Joe")

... and curiously, so does this:

ggplot(df,aes(names))+geom_histogram()+xlim("Bob","Mary","Joe","Frank")

... and even more confusingly, this works perfectly:

ggplot(df,aes(names,..density..,group=1))+geom_histogram()+xlim("Bob","Mary")


This feels like a bug, but perhaps I'm doing something dumb.  Can anyone
clarify?


And while I have your attention: as a ggplot novice, I often find myself
getting cryptic error messages like the one above.  Nearly always this is
because I'm asking it to do something unreasonable, but it often takes me
quite a long time to figure out my error.  Does anyone have general tips for
debugging ggplot commands?  Anything better than summary(p)?


Thanks very much for your help,

-J

	[[alternative HTML version deleted]]

