【问题标题】:How to exclude given figure in the color fill render?如何在颜色填充渲染中排除给定的图形?
【发布时间】:2021-12-10 19:30:56
【问题描述】:

在 R ggplot2/geom_tile 中,如何排除 'month==6 & category==c' 中的数据? (我的意思是数据不加入平铺填充渲染,但仍然保留在图像中)

library(tidyverse)
plot_data <- data.frame(month=c(1,2,3,4,5,6),
category=c("a","b","c","a","b","c"),
value=c(53,20,41,32,67,120000))

plot_data %>% 
  ggplot(aes(x=month,y=category,fill=value))+geom_tile()+
  geom_text(color='white',aes(label=value))+
  scale_fill_gradientn(colors=c('white','yellow','orange','red'))

【问题讨论】:

    标签: r ggplot2 geom-tile


    【解决方案1】:

    您可以在填充刻度上设置limits。在您的情况下,您可能会选择仅填充 0 到 80 之间的值:

    plot_data %>% 
      ggplot(aes(x = month, y = category, fill = value)) +
      geom_tile() +
      geom_text(aes(label = value)) +
      scale_fill_gradientn(colors = c('white', 'yellow', 'orange', 'red'),
                           limits = c(0, 80))
    

    【讨论】:

    • 这就是我想要的,非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2019-04-15
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-05
    相关资源
    最近更新 更多