Home > database >  How to exclude given figure in the color fill render?
How to exclude given figure in the color fill render?

Time:10-26

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

enter image description here

CodePudding user response:

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

enter image description here

  • Related