Точки базовой функции R () могут дублироваться - PullRequest
0 голосов
/ 23 ноября 2018

Я пытался выяснить, почему я вижу только один из двух графиков с нанесением точек () .

set.seed(0)
SSE <- rep(0, 10)
for (i in 1:10){
  km.out <- kmeans(x = iris[,1:4], centers = 3, nstart = i)
  SSE[i] <- km.out$tot.withins
}
plot(1:10, SSE, xlab = "k", ylab = "SSE", type = "b")
km.out$cluster

plot(iris[,1:2], col=(km.out$cluster+1), main="Best solution k = 3", xlab="x1", ylab="x2")
points(km.out$centers, col = 1:2, pch = 8, cex = 2)

plot(iris[,3:4], col=(km.out$cluster+1), main="Best solution k = 3", xlab="x1", ylab="x2")
points(km.out$centers, col = c3:4, pch = 8, cex = 2) # didn't work, not sure why

Первый график имеет точки.

First plot

Второй участок без точек.

Second plot

Кто-нибудь знает, что я делаю не так?

1 Ответ

0 голосов
/ 23 ноября 2018

Точки находятся за пределами диапазона графика.Увеличьте ylim следующим образом:

 plot(iris[,3:4], col=(km.out$cluster+1), main="Best solution k = 3", xlab="x1", ylab="x2", ylim=c(0,4))
 points(km.out$centers, col = 3:4, pch = 8, cex = 2)

И вы увидите все.

Или отрегулируйте сами точки:

 points(km.out$centers[, 3:4], col = 3:4, pch = 8, cex = 2)

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...