0

を使用して 2 つのパネルに結果をプロットする関数を使用していますpar(mfrow = c(1, 2))

3 つの異なるデータセットで関数を実行し、出力を一緒にプロットして、 を使用しているかのように、それぞれが一列になるようにしたいと思いますpar(mfrow = c(3, 2))

関数自体を変更せずにこれを行う方法があれば?

おそらく基本的な問題ですが、非常に助かります。

関数は少し長いですが、関連する部分で PCoA がプロットされます。

# perform classical multidimensional sclaing (PCoA) of the dist matrix      
  acop <- cmdscale(dat.d, k = nrow(as.matrix(dat.d)) - 1, eig = TRUE) # keep n-1 eigenvalues

  axes.tot <- acop$eig # eig are the n eigenvalues computed by cmdscale. Axes are ranked by their 
eigenvalues, so the first axis has the highest eigenvalue, the second axis has the second highest 
eigenvalue, etc.

  inertia <- sum(acop$eig[acop$eig > 0]) 

  percents <- round(as.numeric(100 * axes.tot/inertia), digits = 0) # The eigenvalues represent 
the variance extracted by each axis, here they are expressed as a percentage of the sum of all 
eigenvalues (i.e. total variance).

  par()

  par(mfrow = c(1, 2), pty = "s")

  coord1 <- acop$points[, c(1, 2)] # points is a matrix whose rows give the coordinates of the 
points chosen to represent the dissimilarities

  col.grps <- data.frame(vect.grps, coord1)

  # plot so that the maximum variance is projected along the first axis, then on the second and so 
on

  plot(coord1, asp = 1, cex = 0.1, xlab = paste("Axis 1 ", 

    "(", percents[1], " % variance explained)", sep = ""), 

    ylab = paste("Axis 2 ", "(", percents[2], " % variance explained)", 

      sep = ""), main = "", type = "n", bty = "n")

  abline(h = 0, lty = 2, col = "grey")

  abline(v = 0, lty = 2, col = "grey")

  if (length(vect.grps) == nrow(as.matrix(dat.d))) {

    for (g in 1:length(names.grps)) {

      text(x = coord1[col.grps[, 1] == names.grps[g], 1], 

        y = coord1[col.grps[, 1] == names.grps[g], 2], 

        labels = names.grps[g], col = topo.col[g], cex = 0.7)

    }

  }

  else {

    points(coord1, pch = 19, col = "blue", cex = 0.5)

  }


   coord1 <- acop$points[, c(3, 4)]

 col.grps <- data.frame(vect.grps, coord1)

plot(coord1, asp = 1, cex = 0.1, xlab = paste("Axis 3 ", 

  "(", percents[3], " % variance explained)", sep = ""), 

 ylab = paste("Axis 4 ", "(", percents[4], " % variance explained)", 

   sep = ""), main = "", type = "n", bty = "n")

abline(h = 0, lty = 2, col = "grey")

abline(v = 0, lty = 2, col = "grey")

if (length(vect.grps) == nrow(as.matrix(dat.d))) {

 for (g in 1:length(names.grps)) {

   text(x = coord1[col.grps[, 1] == names.grps[g], 1], 

     y = coord1[col.grps[, 1] == names.grps[g], 2], 

     labels = names.grps[g], col = topo.col[g], cex = 0.7)

 }

  }

  else {

    points(coord1, pch = 19, col = "blue", cex = 0.5)
4

1 に答える 1