答案 0 :(得分:1)
当然,只需映射color
,就像这样:
library(ggplot2)
ggplot(diamonds) +
geom_bar(aes(clarity, fill = color,
# 1) set the border (i.e. the color aesthetic) based on whether the value
# of the relevant variable (which also happens to be called color) is D
color = color=='D')) +
# 2) use a scale such that FALSE is no color and TRUE is black,
# but don't include this in the legend
scale_color_manual(values = c(NA, 'black'), guide=F)
答案 1 :(得分:0)
你可以通过使用scale_color_manual()并指定颜色来做到这一点,在这种情况下" D",黑色和所有其他NA:
library(ggplot2)
d <- ggplot(diamonds) + geom_bar(aes(clarity, fill=color, colour = color)) +
scale_color_manual(values = c("J" = NA,
"I" = NA,
"H" = NA,
"G" = NA,
"F" = NA,
"E" = NA,
"D" = "black"))
d