Using this data:
library(ggplot2)
dd <- data.frame(id = c("A", "A", "B", "B"), prepost = c("pre", "post"),
value = 1:4)
this one works:
qplot(id, value, data = dd, fill = prepost, geom = "bar")
however, the next one gives the indicated error message. The only difference between the two is the addition of group = prepost
to the end of the command; however, since we had already written fill = prepost
that should be the default group anyways.
> qplot(id, value, data = dd, fill = prepost, geom = "bar", group = prepost)
Error in pmin(y, 0) : object 'y' not found
We can fix up the last one by adding stat = "identity"
like this:
qplot(id, value, data = dd, fill = prepost, geom = "bar", group = prepost,
stat = "identity")
I have two questions:
(a) Why does the qplot
which gave the error message not work when the others do work?
(b) If we use a continuous y
aesthetic with geom_bar
then what is supposed to happen if one does not specify stat
? From the first qplot
it seems that in that case it acts as if stat="identity"
but in the presence of group
specifying stat="identity"
or not reveals a difference.
(By the way, this question seems somewhat related although its different enough that it does not seem to answer this question: Issue with ggplot2, geom_bar, and position="dodge": stacked has correct y values, dodged does not)