Hi:
There are a couple of ways you could go:
(1) Define a standalone vector of colors.
(2) Create a factor inside ce containing the vector of colors.
#-----------
library(gcookbook)
library(plyr)
library(ggplot2)
ce <- arrange( cabbage_exp, Date, Cultivar)
ce <- ddply( ce, "Date", transform, label_y = cumsum( Weight))
# (1)
cols <- gl(2, 1, length = 6, labels = c("black", "white"))
ggplot(ce, aes( x = Date, y = Weight, fill = Cultivar)) +
geom_bar( stat ="identity") +
geom_text( aes( y = label_y, label = Weight), vjust = 1.5, colour = cols)
# (2)
ce <- mutate(ce, cols = gl(2, 1, length = 6, labels = c("black", "white"))
ggplot(ce, aes( x = Date, y = Weight, fill = Cultivar)) +
geom_bar( stat ="identity") +
geom_text( aes( y = label_y, label = Weight, colour = cols), vjust = 1.5)
#-------------
In (2), cols is inside aes() because cols is a column of the input
data frame ce. In (1), it is a standalone vector that is not part of
ce so cannot be 'seen' by aes(); therefore, it must be defined outside
of aes().
Method 2 is safer, especially if this is to be reused. (1) is OK for
one-off use at the command line.
Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.