提问人:Rosalin August 提问时间:11/9/2023 更新时间:11/11/2023 访问量:16
使用 vegan 包更改颜色并向 nestedtemp() 图添加标签
Changing colors and adding labels to a nestedtemp() plot using the vegan package
问:
我使用 R 包 vegan 来检查数据集中的嵌套性:
bc_rp <- read.csv("BC_RPc.csv", na.strings = c("","NA"), header=TRUE, check.names = FALSE)
bc_rp
bc <- data.frame(
cell_layer = c("H", "B", "A", "G", "O"),
Np = c(0, 1, 1, 0, 0),
Pn = c(1, 1, 0, 0, 1),
Npn = c(0, 1, 0, 0, 0),
Npnp = c(0, 1, 0, 0, 0),
Pnp = c(1, 0, 0, 0, 0),
Pnpn = c(0, 1, 0, 0, 0)
)
# Renamed the columns to be easier to manipulate and have no special characters
# colnames(hc) <-c('species', 'a','b','c','d','e','f','g')
# Transpose the rows and columns in data.
bc_t <-t(bc)
out_bc_t <- nestedtemp(bc_t)
out_bc_t
#nestedness temperature: 10.24168
#with matrix fill 0.4
plot(out_bc_t, kind="incid")
此代码按预期工作,以生成嵌套温度和绘图。
但是,我希望我可以将绘图的颜色更改为红色以外的颜色,并为每种单元格类型和类别(np、pn 等)添加标签我该怎么做?
答:
0赞
Jari Oksanen
11/11/2023
#1
一个好的起点是函数的文档(try )。的函数似乎有可用于设置颜色的参数,默认为 ,但设置会添加名称(至少根据文档 - 我没有尝试过)。如果这些对您没有帮助,请提出更详细的问题。?nestedtemp
plot
nestedtemp
col
names
names = FALSE
TRUE
评论
0赞
Rosalin August
11/21/2023
谢谢!我试过 col,但它改变了整个图的颜色,所以你看不到它的存在/不存在数据。所以我仍然不确定如何改变颜色。但是“名称 = TRUE”奏效了!所以现在我有了标签,这真的很有帮助。
0赞
Jari Oksanen
11/22/2023
对于颜色,您必须提供调色板。入射图需要两种颜色,温度图需要更宽的调色板,其中第一种颜色是不存在(冷),最后一种颜色是最热的颜色。请参见中的缺省值。plot(..., kind="incidence", col=c("white","black"))
?plot.nestedtemp
评论