Why is ggplot using default colors when others are specified?

ggplot2, histogram, r

Solution

I don't think you can explicitly set colors in `aes`; you need to do it in `scale_fill_manual`, as in the example below:

ggplot(dist.x, aes(x = sim_con)) +
  geom_histogram(colour = "black", binwidth = .01,aes(fill=(sim_con==1.55))) + 
  scale_fill_manual(values=c('TRUE'='darkgreen','FALSE'='firebrick')) +
  theme(legend.position="none")

Problem

I am trying to have ggplot2 show one line of a histogram as a different color than the rest. In this I have been successful; however, ggplot is using the default colors when a different set are specified. I am sure there is an error in my code, but I am unable to determine where it is. The data and code are below: create data ``` library(ggplot2) set.seed(71185) dist.x <- as.data.frame(round(runif(100000, min= 1.275, max= 1.725), digits=2)) colnames(dist.x) <- 'sim_con' ``` start histogram ``` ggplot(dist.x, aes(x = sim_con)) + geom_histogram(colour = "black", aes(fill = ifelse(dist.x$sim_con==1.55, "darkgreen", "firebrick")), binwidth = .01) + theme(legend.position="none") ``` Which results in the following image: I do not want to use the default colors, but instead want to use 'darkgreen' and 'firebrick'. Where is the error in the code? Thanks for any help you can provide.

Original source