简体   繁体   中英

How to exclude given figure in the color fill render?

In R ggplot2/geom_tile, how to exclude the data in 'month==6 & category==c' ? (i mean the data not join the tile fill render, but still keep in the image)

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'))

在此处输入图片说明

You can set limits on the fill scale. In your case, you might for example choose to fill only values between 0 and 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))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM