0

Why does plot behave differently for different data, and how do you control it? My specific example today is getting different output with scaled and non-scaled data. For example

fit <- kmeans(mydata, 4)
plot(mydata, col = fit$cluster)

returns a nice 4x4 scatter matrix plot (mydata is 486x4) but

mydata <- scale(mydata)
fit <- kmeans(mydata, 4)
plot(mydata, col = fit$cluster)

returns a single plot showing variable 1 scatter plotted vs variable 2?

SC.
  • 406
  • 1
  • 6
  • 13

1 Answers1

1

This is because scale() returns a matrix rather than a data.frame. Just convert it back to a data.frame

mydata <- data.frame(scale(mydata))
MrFlick
  • 195,160
  • 17
  • 277
  • 295