Hi!
I'm new to using kmeans and clustering in R. I've been trying to figure out how to visualize the clusters in a pretty and presentable way.
I've attached a table of what the data looks like. There are more column variables but this sample should do. This data is originally from a survey and answers were recorded as 0s and 1s and then clustered using kmeans accordingly.
I'd appreciate any advice or help on how to plot this.
I think the easiest way to do this would be by some type of ordination, and then plotting the ordination with the text labels indicating which cluster a data point is in.
I will give an example using data included in the vegan program. I will not include steps like standardizing data before the ordination or indicate what ordination method should be used. That will vary depending on the type of data.
library(vegan)
data(varespec)
ord=metaMDS(varespec,k=3,engine="monoMDS") #create ordination
km=kmeans(varespec,3) #kmeans clustering with 3 groups
fig=ordiplot(ord)
ordiplot(fig,type="n") #plot ordination
text(fig,"sites",km$cluster,cex=0.8) #add cluster membership as text
That will give you something basic, like this:
Which is maybe not too pretty, but easily interpretable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.