我使用R中的vegan{}
包为Gower相似性指数绘制了质心,并希望根据原始数据集中的因子对椭圆填充进行颜色编码。质心用于月份 - 站点组合(这些是我想要绘制的唯一质心;请参阅下面的数据示例),但我希望按月对颜色进行颜色编码,然后在第二个图中按网站进行颜色编码,以显示差异因素之间。目前代码如下:
dat.fac<-dat[,1:7] ##factors
dat.mgower <- vegdist(decostand(dat[,8:34], "log"), "altGower")
ord<-capscale(dat.mgower~1) #Does the PCO
plot(ord, display = "sites", type = "n")
#for i in
stats<-with(dat.fac,
ordiellipse(ord, Site_TP, kind="se", conf=0.95,
lwd=2, draw = "polygon",col="#0000ff22",border = "blue"))
带有质心的MDS图如下所示:
我希望能够根据a)场地和b)季节(5月对9月)对质心的填充进行颜色编码。我尝试过使用col=c("#0000ff22","#CAFF7022",...)
,但这不起作用,因为省略号的坐标位于ord
。我也试过了
with(dat.fac,ordiellipse(ord, Site_TP[1:54], kind="se", conf=0.95,
lwd=2, draw = "polygon",col="#0000ff22",border = "blue"))
让ceentroids的前半部分为一种颜色(前半部分都来自同一个月),但这会导致错误“cov.wt(X,W)中的错误:'x'必须包含只有有限值。“ 救命! 感谢。
数据如下所示:
structure(list(Core_num = structure(c(39L, 50L, 61L, 70L, 71L,
72L, 73L, 74L, 75L, 76L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L,
93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L,
105L, 106L, 107L, 108L, 112L, 113L, 115L, 116L, 117L, 118L, 119L,
120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L, 130L,
131L, 132L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 17L, 18L,
19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L,
32L, 33L, 34L, 35L, 36L, 37L, 38L, 40L, 44L, 45L, 46L, 47L, 48L,
49L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 62L, 63L,
64L, 65L, 66L), .Label = c("152", "153", "154", "155", "156",
"157", "158", "159", "160", "161", "162", "163", "164", "165",
"166", "167", "168", "169", "170", "171", "172", "173", "174",
"175", "176", "177", "178", "179", "180", "181", "182", "183",
"184", "185", "186", "187", "188", "189", "19", "190", "191",
"192", "193", "194", "195", "196", "197", "198", "199", "20",
"200", "201", "202", "203", "204", "205", "206", "207", "208",
"209", "21", "210", "211", "212", "213", "214", "215", "216",
"217", "22", "23", "24", "25", "26", "27", "28", "29", "30",
"31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41",
"42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52",
"53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63",
"64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74",
"75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "L1",
"L10", "L11", "L12", "L13", "L14", "L15", "L16", "L17", "L18",
"L2", "L20", "L21", "L22", "L23", "L24", "L25", "L26", "L27",
"L28", "L3", "L4", "L5", "L6", "L7", "L9"), class = "factor"),
Cage_num = c(47L, 46L, 45L, 2L, 24L, 1L, 23L, 25L, 3L, 61L,
5L, 6L, 27L, 49L, 4L, 7L, 48L, 29L, 28L, 26L, 8L, 10L, 51L,
50L, 9L, 11L, 30L, 33L, 31L, 32L, 52L, 53L, 54L, 55L, 18L,
60L, 41L, 38L, 63L, 19L, 16L, 17L, 40L, 44L, 43L, 21L, 20L,
22L, 39L, 62L, 65L, 66L, 42L, 64L, 9L, 54L, 31L, 52L, 10L,
53L, 33L, 32L, 8L, 11L, 55L, 30L, 66L, 64L, 21L, 20L, 43L,
42L, 44L, 65L, 63L, 18L, 16L, 22L, 62L, 61L, 38L, 19L, 60L,
17L, 39L, 40L, 41L, 3L, 24L, 25L, 2L, 23L, 1L, 46L, 47L,
45L, 5L, 28L, 48L, 6L, 51L, 50L, 4L, 7L, 29L, 49L, 26L, 27L
), Treatment = structure(c(3L, 3L, 3L, 1L, 2L, 1L,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, 0, 0, 0, 0, 0, 0, 0, 291, 291, 291,
291, 291, 291, 291, 291, 291, 669, 669, 669, 669, 669, 291,
291, 669, 669, 669, 669, 86, 86, 86, 86, 86, 86, 86, 86,
86, 86, 86, 86, 806, 806, 806, 806, 806, 806, 806, 806, 428,
428, 428, 806, 428, 428, 428, 428, 428, 428, 428, 428, 428,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0), Time_point = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("May",
"September"), class = "factor"), Site_TP = structure(c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 10L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 14L, 14L, 1L, 1L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 8L, 8L, 8L, 8L, 8L, 10L, 10L, 8L, 8L, 8L,
8L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 11L, 11L, 11L, 9L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L), .Label = c("M1_May", "M1_September", "M2_May", "M2_September",
"R07_May", "R08_Feb_May", "R08_Jul_May", "R09_May", "R09_September",
"R10_May", "R10_September", "R11_5m_May", "R11_5m_September",
"R11_May", "R11_September"), class = "factor"), Spionidae = c(0,
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 19, 7, 2,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Nereididae = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Syllidae = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 8, 0, 0, 0, 3, 1, 0, 0, 0, 4, 4, 0, 0,
0, 1, 0, 1, 4, 1, 0, 0, 1, 1, 2, 2, 0, 1, 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L, 0L, 0L, 4L,
0L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("Core_num",
"Cage_num", "Treatment", "Site", "Days_Since_Removal", "Time_point",
"Site_TP", "Spionidae", "Nereididae", "Syllidae", "Opheliidae",
"Cossuridae", "Sternaspidae", "Sabellariidae", "Sabellidae",
"Capitellidae", "Dorvillidae", "Cirratulidae", "Oligochaeta",
"Nemertea", "Nematoda", "Platyhelminthes", "Sipuncula", "Ostracoda",
"Decapoda", "Amphipoda", "Isopoda", "Copepoda", "Tanaidacea",
"HYRDOZOA", "ANTHOZOA", "Cnidarian_larvae", "Tunicata", "Mollusca"
), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 19L,
20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L,
33L, 34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 46L, 47L, 49L,
50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L,
76L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 93L, 94L,
95L, 96L, 97L, 98L, 99L, 100L, 101L, 102L, 103L, 104L, 105L,
109L, 110L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L,
120L, 121L, 122L, 123L, 124L, 125L, 126L, 127L, 128L, 129L), class = "data.frame")
答案 0 :(得分:2)
理想情况下,函数可以返回椭圆中使用的x和y坐标。以下是ordiellipse()
的简单修改,它将xy
添加到函数输出的每个列表元素中:
ordiellipse2 <-
function (ord, groups, display = "sites", kind = c("sd", "se"),
conf, draw = c("lines", "polygon", "none"),
w = weights(ord, display), col = NULL, alpha = 127,
show.groups, label = FALSE, ...)
{
weights.default <- function(object, ...) NULL
kind <- match.arg(kind)
draw <- match.arg(draw)
pts <- scores(ord, display = display, ...)
## ordiellipse only works with 2D data (2 columns)
pts <- as.matrix(pts)
if (ncol(pts) > 2)
pts <- pts[ , 1:2, drop = FALSE]
if (ncol(pts) < 2)
stop("ordiellipse needs two dimensions")
w <- eval(w)
if (length(w) == 1)
w <- rep(1, nrow(pts))
if (is.null(w))
w <- rep(1, nrow(pts))
## make semitransparent fill
if (draw == "polygon" && !is.null(col))
col <- rgb(t(col2rgb(col)), alpha = alpha, maxColorValue = 255)
if (!missing(show.groups)) {
take <- groups %in% show.groups
pts <- pts[take, , drop = FALSE]
groups <- groups[take]
w <- w[take]
}
out <- seq(along = groups)
inds <- names(table(groups))
res <- list()
if (label)
cntrs <- names <- NULL
## Remove NA scores
kk <- complete.cases(pts)
for (is in inds) {
gr <- out[groups == is & kk]
if (length(gr) > 2) {
X <- pts[gr, ]
W <- w[gr]
mat <- cov.wt(X, W)
if (kind == "se")
mat$cov <- mat$cov/mat$n.obs
if (missing(conf))
t <- 1
else t <- sqrt(qchisq(conf, 2))
xy <- vegan:::veganCovEllipse(mat$cov, mat$center, t)
if (draw == "lines")
vegan:::ordiArgAbsorber(xy, FUN = lines,
col = if(is.null(col)) par("fg") else col,
...)
else if (draw == "polygon")
vegan:::ordiArgAbsorber(xy[, 1], xy[, 2], col = col, FUN = polygon,
...)
if (label && draw != "none") {
cntrs <- rbind(cntrs, mat$center)
names <- c(names, is)
}
mat$scale <- t
mat$xy <- xy # this is the only substantive change I made
res[[is]] <- mat
}
}
if (label && draw != "none") {
if (draw == "lines")
vegan:::ordiArgAbsorber(cntrs[,1], cntrs[,2], labels=names, col = col,
FUN = text, ...)
else
vegan:::ordiArgAbsorber(cntrs, labels = names, col = NULL,
FUN = ordilabel, ...)
}
class(res) <- "ordiellipse"
invisible(res)
}
现在您可以根据您的示例创建stats
对象,但可以自行指定draw = "none", because you'll want to play with
stats`以完全控制椭圆绘图(无需指定图形参数):
stats<-with(dat.fac, ordiellipse2(ord, Site_TP, kind = "se", conf = 0.95, draw = "none"))
现在请注意,stats具有相同的形式,但每个椭圆都有一个元素xy
:
names(stats[[1]])
[1] "cov" "center" "n.obs" "wt" "scale" "xy"
您可以使用polygon()
函数在循环中绘制这些图,但更好的方法是将所有xy
坐标放在一个matrix
或data.frame
中,以便您只需拨打polygon()
一次,但使用矢量化参数,例如col
,lwd
。我将使用xy
提取lapply()
矩阵,然后将它们合并为data.frame
。键是用NA
s分隔各个椭圆,因此多边形绘图知道一个停止和下一个停止的位置:
xy.mat <- t(as.data.frame(lapply(stats, function(x){
t(rbind(x$xy, NA))
})))
绘图变得容易:
plot(ord, display = "sites", type = "n")
polygon(xy.mat[, 1], xy.mat[, 2], col = c(rep("#0000ff20", 5), rep("#ff000030", 5)), border = c(rep("blue", 5), rep("red", 5)))
现在只需要正确地为polygon()
排序图形参数。