具有连续值的栅格数据分箱绘制是地学绘图里的常用方法,python和R里面都可以比较简单地实现
下面介绍R的实现方式,主要是scale_fill_stepsn/scale_fill_binned的函数设置。
scale_fill_stepsn(name = "Priority ranks", # 改图例名称
labels = rev(c("2.5%", "5%", "10%", "17%","30%","50%","75%","100%")), # 改图例标签
breaks = rev(1-c(0, 0.025, 0.05, 0.1,0.17, 0.30, 0.50,0.75)), # 设置源数据的间断点,用于分箱
colors = c("#9e0142", "#f46d43", "#fdae61", "#fee08b", "#ffffbf", "#abdda4", "#66c2a5", "#3288bd"), #设置每两个间断点之间的颜色
values = (1-c(0, 0.025, 0.05, 0.1,0.17, 0.30, 0.50,0.75,1)) # 原数据的范围,默认可以不设置
)
也可以使用scale_fill_binned函数,但是其可修改的参数较少,换颜色比较麻烦。
scale_fill_binned(name = "Priority ranks",
labels = rev(c("2.5%", "5%", "10%", "17%","30%","50%","75%","100%")),
breaks = rev(1-c(0, 0.025, 0.05, 0.1,0.17, 0.30, 0.50,0.75)),
type = "viridis")+