R-code-snippets
R-code-snippets copied to clipboard
clustergram.plot.matlines requires plyr - use do.call instead of plyr::ldply
I use a modified version of this function and thought I'd share w/ others in case it's ever helpful. Originally, the code within the if block that checks if add.center.points is true, requires the plyr library. I don't usually have that library installed so I've modified the snipped to use do.call instead.
clustergram.plot.matlines <- function(X, Y, k.range,
x.range, y.range, COL,
add.center.points, centers.points) {
plot(
0,
0,
col = "white",
xlim = x.range,
ylim = y.range,
axes = F,
xlab = "Number of clusters (k)",
ylab = "PCA weighted Mean of the clusters",
main = c("Clustergram of the PCA-weighted Mean of", "the clusters k-mean clusters vs number of clusters (k)")
)
axis(side = 1, at = k.range)
axis(side = 2)
abline(v = k.range, col = "grey")
matlines(t(X), t(Y), pch = 19, col = COL, lty = 1, lwd = 1.5)
if (add.center.points) {
xx <- do.call(rbind, centers.points)
points(xx$y ~ xx$x, pch = 19, col = "red", cex = 1.3)
}