【问题标题】:Legend in species accumulation plots物种积累图中的传说
【发布时间】:2020-06-25 13:26:02
【问题描述】:

如何为该图表添加标题? 我尝试了下面的命令,但我的图表消失了

library(vegan)
data(BCI)

sp1 <- specaccum(BCI, "random")
sp2 <- specaccum(BCI, "coleman")

plot(sp1, ci.type="poly", col="blue", lwd=2,
     ci.lty=0, ci.col = rgb(.5, .5, .5, 0.5))
plot(sp2, ci.type="poly", col="yellow",lwd=2,
     ci.lty=0, ci.col = rgb(.5, .5, .5, 0.5), add=TRUE)
legend(x="top", legend=sp1)

【问题讨论】:

    标签: r graph legend vegan


    【解决方案1】:

    您的情节消失的原因是您试图创建一个包含sp1 全部内容的图例,这是一个大型数字对象。大概这不是您想要的,您只是在寻找 text "sp1" 出现在图例中。您需要指定要作为标签添加到图例中的字符串向量,以及颜色向量。

    注意,我还在 first 调用 plot 时使用 main = "sp1" 为该图添加了标题:

    library(vegan)
    data(BCI)
    
    sp1 <- specaccum(BCI, "random")
    sp2 <- specaccum(BCI, "coleman")
    
    plot(sp1, ci.type="poly", col="blue", lwd=2,
         ci.lty=0, ci.col = rgb(.5, .5, .5, 0.5), main = "sp1")
    plot(sp2, ci.type="poly", col="yellow",lwd=2,
         ci.lty=0, ci.col = rgb(.5, .5, .5, 0.5), add = TRUE)
    legend(x = "bottomright", legend = c("sp1", "sp2"), fill = c("blue", "yellow"))
    

    reprex package (v0.3.0) 于 2020 年 3 月 13 日创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      相关资源
      最近更新 更多