画柱状图时,想高亮显示某个元素:
library(tidyverse)
d <- tibble(name = c("Alice","Bob","Chat","Dave","Eve","Falbo"),
score = c(70,80,60,50,90,77))
d
d %>%
ggplot(aes(x = score, y = reorder(name,score)))+ #对y进行排序
geom_col(
aes(fill = score == max(score)), #将color进行映射
show.legend = FALSE
)+
scale_fill_manual(values = c("grey","red"))
image.png
参考资料:
perlatex: ggplot2画图中使用高亮
网友评论