我正在努力在网格中绘制积雪深度的数据集,深度作为一个连续变量。但是,网格中的一些地块被部分覆盖。这些被划分为>50%和<50%的地块,覆盖的变量与深度测量相同,标记为'over‘和'under’。
当我尝试使用ggplot 2绘制数据时:
myplot <- ggplot()+
geom_tile(data=table, aes(x=factor(Row), y=Colum, fill= Snow_depth))+
scale_fill_gradient(low="#0066CC", high="#FF3333")当然,我得到了错误:
Error: Discrete value supplied to continuous scale我如何包含这些离散的数据,并给它们一个清晰的颜色标签,以便所有信息都显示在同一张图像中?
发布于 2020-05-18 22:11:41
编辑:
在进一步考虑之后,一种方法可能是在覆盖的地块上使用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")

https://stackoverflow.com/questions/61870808
复制相似问题