柱状图[高亮显示某个变量]

2021-03-06  本文已影响0人  北欧森林

画柱状图时,想高亮显示某个元素:

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画图中使用高亮

上一篇下一篇

猜你喜欢

热点阅读