I'm trying to colour geom_bar
according to the number of the sample ifelse(total > 90, "#FC2D00", "#008EFC")
. In other words, if the total
> 90, the bar should be red
but total
< 90, it should be blue.
type = c("aa", "bb", "cc")
total = c(110, 90, 89)
df = data.frame(type, total)
df %>%
ggplot2::ggplot(aes(x = type, y = total)) +
geom_bar(position = "dodge",
stat = "identity")
I tried
df %>%
ggplot2::ggplot(aes(x = type, y = total)) +
geom_bar(position = "dodge",
stat = "identity",
fill = (ifelse(
levels(studies$total > 90, "#FC2D00", "#008EFC"))))
and also
df %>%
mutate(fill = ifelse(levels(total > 90, "#FC2D00", "#008EFC"))) %>%
ggplot2::ggplot(aes(x = type, y = total)) +
geom_bar(position = "dodge",
stat = "identity",
fill = fill)
but it still not working. I'm not sure what is the problem.