我下面有一个代码,我想用所选的 colored颜色 给前3个上色.非常感谢.
library(ggplot2)
library(dplyr)
df <- data.frame(dose = c("D0.5", "D1", "D2", "D3", "D4", "D5"),
len = c(4.2, 10, 29.5, 5, 7, 15))
df <- dplyr::mutate(df, top3 = rank(-len) %in% 1:3)
# Basic barplot
p <- ggplot(data = df, aes(x = reorder(dose, -len), y = len)) +
geom_bar(stat = "identity", fill = ifelse(df$top3 == TRUE, c("blue", "yellow", "green"), "grey50")) +
#color = ifelse(df$top3 == TRUE, c("red", "yellow", "green"), "grey50")) +
coord_flip()
p