I'm stuck on plotting my data with ggplot. The outpit I have now is 16 obs. of 3 variables. I used unlist to make it a different data type but I still get errors to plot. My code:
library(datasets)
data(iris)
cluster_data<-iris[-5]
calcss <- function(missingvar,kval) {
cluster<-kmeans(cluster_data[-missingvar],kval,nstart=100)
TotWithinSS<-cluster$tot.withinss
return(TotWithinSS)
}
kvals=list()
sumsqs=list()
missvars=list()
for(k in 2:5){
for(var in 1:4){
kvals=rbind(kvals,k)
sumsqs=rbind(sumsqs,calcss(var,k))
missvars=rbind(missvars,var)
}
}
out<-data.frame(kvals,missvars,sumsqs)
ggplot(data=out,aes(missvars,sumsqs,color=kvals))
The error says:
Don't know how to automatically pick scale for object of type list. Defaulting to continuous. Don't know how to automatically pick scale for object of type list. Defaulting to continuous. Don't know how to automatically pick scale for object of type list. Defaulting to continuous.
kvals, sumsqs, missvars
asnumeric(0)
not aslist()
. And add a geom to your plot, such as+geom_point()
– Andrew Gustar