【发布时间】:2021-03-04 06:00:36
【问题描述】:
我正在尝试根据样本编号ifelse(total > 90, "#FC2D00", "#008EFC") 为geom_bar 着色。换句话说,如果total > 90,条形应该是red,但total
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")
我试过了
df %>%
ggplot2::ggplot(aes(x = type, y = total)) +
geom_bar(position = "dodge",
stat = "identity",
fill = (ifelse(
levels(studies$total > 90, "#FC2D00", "#008EFC"))))
还有
df %>%
mutate(fill = ifelse(levels(total > 90, "#FC2D00", "#008EFC"))) %>%
ggplot2::ggplot(aes(x = type, y = total)) +
geom_bar(position = "dodge",
stat = "identity",
fill = fill)
但它仍然无法正常工作。我不确定是什么问题。
【问题讨论】: