复现Nature子刊Whittaker生物群系图

文章介绍了Whittaker生物群系分类法,由生态学家RobertWhittaker提出,基于降水和温度对生态系统进行划分。通过R语言的plotbiomes包,展示了如何用两行代码绘制生物群落分布图,并提供了修改颜色和形状的方法。此外,还详细解释了如何复现Nature子刊中的图表,包括添加点以表示样本数据和映射高程信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Whittaker生物群系,也称为生态系统分类法,是基于地理分布和环境条件等因素将地球表面的生态系统分为不同类型的系统。这种分类方法由美国生态学家罗伯特·惠特克(Robert Whittaker)于1962年提出,目的是为了更好地了解和描述生态系统的多样性和功能。

Whittaker使用两个因素对生物群落进行分类:降水和温度

image-20230314233906578
image-20230314233906578

Whittaker生物群系根据气候和植被类型的组合,将地球表面的生态系统划分为五种类型:热带雨林、温带针叶林、温带落叶阔叶林、草原和沙漠。其中,热带雨林分布在赤道附近,气候温暖湿润,植被丰富多样;温带针叶林分布在北半球和南极洲的较高纬度地区,气候寒冷,植被以针叶树为主;温带落叶阔叶林分布在中、高纬度地区,气候四季分明,植被以落叶阔叶树为主;草原分布在中、低纬度地区,气候干燥,植被以草原为主;沙漠分布在低纬度地区,气候干燥,植被稀疏。

下图是一张发表在Nature子刊的图,用于展示不同采样点的气温、降水、高程和所属群落,信息丰富美观。

image-20230314234056033
image-20230314234056033

来看看如何实现

R语言plotbiomes包

用两行代码就能进行一个最简单的实现:

library(plotbiomes)
whittaker_base_plot()
image-20230314234435011
image-20230314234435011

该绘制基于ggplot,可以用ggplot实现相同的结果:

library(plotbiomes)
library(ggplot2)

plot_1 <- ggplot() +
  # add biome polygons
  geom_polygon(data = Whittaker_biomes,
               aes(x    = temp_c,
                   y    = precp_cm,
                   fill = biome),
               # adjust polygon borders
               colour = "gray98",
               size   = 1) +
  theme_bw()
plot_1
alt

Whittaker_biomes是绘制的基本数据,如果考虑修改形状,可以修改该数据:

image-20230314234635486
image-20230314234635486

进一步修改颜色,如使用Whittaker_biomes的经典颜色,

Ricklefs_colors是包附带的预定义颜色矢量plotbiomes。这些是Ricklefs, RE (2008)中使用的颜色:

Ricklefs_colors
plot_2 <- plot_1 +
  # fill the polygons with predefined colors
  scale_fill_manual(name   = "Whittaker biomes",
                    breaks = names(Ricklefs_colors),
                    labels = names(Ricklefs_colors),
                    values = Ricklefs_colors)
plot_2

alt

基于ggplot图层,可以进行更多细节修饰,与ggplot图层语法一起使用:

whittaker_base_plot() + theme_bw()
  • 可以使用不同的配色来增加美观,如使用RColorBrewer包

  • 第二种我使用了自定义调色板

library(RColorBrewer)

# the main rule - create 9 colors for the 9 biomes

# failed trial with RColorBrewer :)
my_palette_1 <- rev(brewer.pal(n = 9, name = "BrBG"))
whittaker_base_plot(color_palette = my_palette_1)

# this seems a better approach - interpolate 9 colors from given main 3  
my_palette_2 <- colorRampPalette(colors = c("#F5F5F5",  "#01665E""#8C510A"))(9)
whittaker_base_plot(color_palette = my_palette_2)
alt

上面使用whittaker_base_plot()封装的方法,可以用ggplot自定义:

names(my_palette_2) <- names(Ricklefs_colors)

ggplot() +
  # add biome polygons
  geom_polygon(data = Whittaker_biomes,
               aes(x    = temp_c,
                   y    = precp_cm,
                   fill = biome),
               # adjust polygon border
               colour = "gray98",
               size   = 1) +
  # fill the polygons with desired colors
  scale_fill_manual(name   = "Whittaker biomes",
                    breaks = names(Ricklefs_colors),
                    labels = names(Ricklefs_colors),
                    values = my_palette_2)
alt

子刊结果复现

为了复现子刊效果,还需要添加一些点

image-20230314235120540
image-20230314235120540

添加随机点,生成随机位置并从 WorldClim 数据中提取温度和降水量。

library(raster)
library(maptools)

path <- system.file("extdata""temp_pp.tif", package = "plotbiomes")
temp_pp <- raster::stack(path)
names(temp_pp) <- c("temperature""precipitation")

data(wrld_simpl) # load world polygons from maptools

wrld_simpl <- wrld_simpl[wrld_simpl$NAME != "Antarctica", ]

set.seed(66) # random number generator
points <- sp::spsample(x = wrld_simpl, n = 50, type = "random")

extractions <- raster::extract(temp_pp, points, df = TRUE)

extractions$temperature <- extractions$temperature/10

extractions$precipitation <- extractions$precipitation/10
extractions$Elevation <- runif(10) * 100
plot(temp_pp[[1]]/10); points(points)
plot(temp_pp[[2]]); points(points)
image-20230314235247536
image-20230314235247536
image-20230314235253850
image-20230314235253850

在whittaker_base_plot封装的基础上叠加点:

whittaker_base_plot() +
  # add the temperature - precipitation data points
  geom_point(data = extractions, 
             aes(x = temperature, 
                 y = precipitation), 
             size   = 3,
             shape  = 21,
             colour = "gray95"
             fill   = "black",
             stroke = 1,
             alpha  = 0.5) +
  theme_bw()
alt

子刊中的图还映射了不同颜色的高程,并且有白色边界,很美观

点的边界color和背景fill的颜色映射很有创意,也相对麻烦,因为fill已经用于生物群系多边形,并且ggplot2只允许一个scale。

所以,我们不能使用两个不同的fill映射。不过,有一个解决方法:

一个解决方案是调用两次geom_point(官方文档ggplot2 中的 6.4.1 图层和图例:用于数据分析的精美图形)。

第一次调用设置点的边界线,第二次调用点着色。

plot_3 <- whittaker_base_plot() +
  geom_point(data = extractions,
             aes(x = temperature,
                 y = precipitation),
             shape  = 21,
             stroke = 1, # acts as the thickness of the boundary line
             colour = "gray95"# acts as the color of the boundary line
             size   = 3.5) +
  geom_point(data = extractions,
             aes(x = temperature,
                 y = precipitation,
                 color = Elevation),
             shape = 16,
             size  = 3,
             alpha = 0.5) +
 scale_color_viridis_c()
plot_3 + theme_bw()
alt

最后用ggplot图层语言综合修饰,把图例放到边框内:

my_plot <- plot_3 +
  # Optional - Overwrite axis ranges (the scale warning is expected):
  # - set range on OY axes and adjust the distance (gap) from OX axes
  scale_y_continuous(name = 'Precipitation (cm)',
                     limits = c(min = -5, max = ceiling(max(460, extractions$precipitation)/10)*10) ,
                     expand = c(0, 0)) +
  # - set range on OX axes and adjust the distance (gap) from OY axes
  scale_x_continuous(name = expression("Temperature " ( degree*C)),
                     limits = c(min = floor(min(-20, extractions$temperature)/5)*5, max = 30.5),
                     expand = c(0, 0)) +
  coord_fixed(ratio = 1/10) + # aspect ratio, expressed as y / x
  theme_bw() +
  theme(
    legend.justification = c(0, 1), # pick the upper left corner of the legend box and
    legend.position = c(0, 1), # adjust the position of the corner as relative to axis
    legend.background = element_rect(fill = NA), # transparent legend background
    legend.box = "horizontal"# horizontal arrangement of multiple legends
    legend.spacing.x = unit(0.5, units = "cm"), # horizontal spacing between legends
    panel.grid = element_blank() # eliminate grids
  )
  my_plot
image-20230314235625571
image-20230314235625571

与子刊原图基本一致:

image-20230314235712206
image-20230314235712206

Whittaker生物群系分类方法不仅考虑了植物和动物的组成,还考虑了环境因素对生态系统的影响。它为生态学研究提供了一个框架,使我们能够更好地了解不同生态系统的特点和功能,更好地保护和管理生态系统。

本文由 mdnice 多平台发布

### R语言中的插值方法及其函数 #### 1. `approx` 函数 R语言中的 `approx` 函数提供了一种简单而有效的线性插值方法。此函数可以根据已知数据点生成新的数据点,适用于一维插值场景[^1]。 以下是使用 `approx` 进行线性插值的一个示例: ```r # 定义原始数据 df <- data.frame(x = c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20), y = c(4, 7, 11, 16, 22, 29, 38, 49, 63, 80)) # 执行线性插值 interp_result <- approx(df$x, df$y, xout = seq(min(df$x), max(df$x), by = 0.5)) # 查看结果 print(interp_result) ``` 上述代码中,`xout` 参数指定了需要计算的新数据点的位置,最终返回的结果是一个列表,包含插值后的 `x` 和对应的 `y` 值[^5]。 --- #### 2. Lagrange 插值法 Lagrange 插值是一种经典的数值分析方法,它可以通过给定的离散数据点构造一个多项式函数来逼近这些数据点。在 R 中,可以手动实现 Lagrange 插值算法[^2]。 以下是一个简单的 Lagrange 插值实现示例: ```r lagrange_interpolation <- function(x_points, y_points, new_x) { n <- length(x_points) result <- numeric(length(new_x)) for (i in 1:length(new_x)) { L <- rep(0, n) for (j in 1:n) { product <- 1 for (k in 1:n) { if (k != j) { product <- product * ((new_x[i] - x_points[k]) / (x_points[j] - x_points[k])) } } L[j] <- y_points[j] * product } result[i] <- sum(L) } return(result) } # 测试数据 x_points <- c(1, 2, 4) y_points <- c(1, 4, 16) # 新的插值点 new_x <- c(1.5, 3) # 计算插值结果 result <- lagrange_interpolation(x_points, y_points, new_x) print(result) ``` 这段代码实现了 Lagrange 插值的核心逻辑,并允许用户指定任意数量的新插值点。 --- #### 3. 克里金插值(Kriging) 虽然克里金插值通常更常用于 Python 的地理数据分析领域[^3],但在 R 中也可以通过特定包(如 `gstat` 或 `automap`)实现空间数据的克里金插值。 下面展示了一个基本的例,说明如何在 R 中设置并运行克里金插值: ```r library(gstat) # 创建样本数据集 data(meuse) coordinates(meuse) <- ~x+y # 设置变量模型 v <- variogram(log(zinc)~1, meuse) m <- fit.variogram(v, model = vgm(1, "Sph", 900, 1)) # 执行克里金插值 grd <- spsample(as(extent(meuse), "SpatialPolygons"), type="regular", cellsize=50) kriged <- krige(log(zinc)~1, meuse, grd, model=m) # 可视化结果 spplot(kriged["var1.pred"]) ``` 以上代码展示了如何加载数据、拟合变差函数以及执行克里金插值的过程。 --- #### 总结 R语言支持多种插值方法,包括但不限于: - **`approx` 函数**:适合快速完成一维线性插值任务。 - **Lagrange 插值**:能够构建高阶多项式以精确匹配有限个数据点。 - **克里金插值**:主要用于处理带有空间依赖性的多维数据。 每种方法都有其适用范围和局限性,在实际应用中需根据具体需求选择合适的工具。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地学万事屋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值