编辑:
在考虑了更多之后,一种方法可能是使用ggpattern
覆盖图上的模式:
set.seed(3)
table <- data.frame(Row = rep(1:9,times=9), Colum = rep(1:9,each=9),
Snow_depth = runif(81,10,100),
Cover = as.logical(round(runif(81,0,1),0)))
#remotes::install_github("coolbutuseless/ggpattern")
library(ggpattern)
library(ggplot2)
ggplot(data=table, aes(x=as.factor(Row), y=as.factor(Colum))) +
geom_tile(aes(fill= Snow_depth)) +
scale_fill_gradient(low="#0066CC", high="#FF3333") +
geom_tile_pattern(aes(pattern_alpha = Cover),
fill = NA, pattern = 'crosshatch',
pattern_fill = "black",
pattern_angle = 45,
pattern_density = 0.1,
pattern_spacing = 0.025,
pattern_key_scale_factor = 0.5) +
scale_pattern_alpha_discrete(range = c(0,0.5), labels = c("No","Yes")) +
labs(x = "Row",y = "Column")
