【问题标题】:How to make a multi-species vegetation density transect plot in r如何在r中制作多物种植被密度样带图
【发布时间】:2020-10-26 20:30:49
【问题描述】:

我想制作一个图形,显示沿样带的多个物种的覆盖密度。这里的图像风格的东西。每个物种都有水平行,并且在横断面的每个点上都有一个密度值(然后我将沿着顶部绘制高程图)。

old figure I am trying to update/replicate, ignore the scale legend

这是一个样带的示例数据集,假设在 10 个样方上采集了 6 个物种的覆盖密度。

Species <- c("S1", "S2", "S3","S4","S5","S6")
Q1 <- c(0,0,0,1,1,0)
Q2 <- c(0,0,1,2,1,0)
Q3 <- c(0,0,1,3,2,4)
Q4 <- c(0,2,1,4,2,4)
Q5 <- c(0,3,0,2,1,4)
Q6 <- c(1,4,0,1,2,5)
Q7 <- c(2,5,0,0,1,1)
Q8 <- c(3,1,0,1,2,0)
Q9 <- c(4,0,0,0,1,0)
Q10 <- c(1,0,0,0,2,0)
df= data.frame(Species, Q1,Q2,Q3,Q4,Q5,Q6,Q7,Q8,Q9,Q10)```

【问题讨论】:

    标签: r ggplot2 plot


    【解决方案1】:

    是的,我想说类似的话,虽然方式略有不同...

    df2 <- gather(df, key = "Point", value = "Density", -1)
    
    ggplot(df2, aes(x = Point, y = Density))+
      geom_col()+
      theme_classic()+
      facet_grid(rows = vars(Species))
    
    

    【讨论】:

    • 不错。您可能需要在 x 轴上重新排序样方:目前您有 Q1、Q10、Q2 等
    【解决方案2】:

    也许是这样的?

    library(dplyr)
    library(tidyr)
    library(ggplot2)
    
    pivot_longer(df, -1) %>%
      ggplot(aes(factor(name, unique(name)), value)) + 
      geom_col(fill = "gray10") +
      facet_grid(Species~.) +
      scale_x_discrete(expand = c(0.2, 0.2)) +
      theme_void() +
      theme(plot.margin = margin(50, 20, 20, 20),
            panel.spacing = unit(30, "points"),
            strip.text = element_text(size = 16))
    

    reprex package (v0.3.0) 于 2020 年 10 月 26 日创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-14
      • 2014-08-25
      • 2022-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      相关资源
      最近更新 更多