0
我有看起来像名为(inputdata_transaction_cluster)的数据帧:如何使用绘图R突出显示图中特定聚类的中心(K-均值聚类)?
我成功地绘制了使用聚类分析plotly读该数据帧中的曲线图(K均值聚类)。 我的代码如下:
nClust <- 3
kmeans_output <- kmeans(inputdata_transaction_cluster, centers = nClust)
inputdata_transaction_cluster$cluster = kmeans_output$cluster
cols <- brewer.pal(nClust, "Set1")
for(i in 1:nClust){
inputdata_transaction_cluster$color[inputdata_transaction_cluster$cluster == i] <- cols[i]
}
plot_ly(inputdata_transaction_cluster, x =~timeStamp, y =~elapsed,type="scatter", mode = "markers", showlegend = FALSE,
hoverinfo = "x+y+text", text =~paste("Cluster:", cluster),
marker = list(opacity = 0.6,
color =~color,
size = 15,
line = list(color = "#262626", width = 3)))%>%
layout(
title = "CLUSTER",
xaxis = list(
title = ""),
yaxis = list(
title = "RESPONSE TIME")
)%>%
layout(xaxis=ax,yaxis = ay) %>%
layout(hovermode = "closest",
showlegend = F,
title = paste("CLUSTER DIAGRAM :",unique(inputdata_transaction1$label)),
titlefont = list(color = "rgb(30,144,255)", size = 18))
我得到一个看起来像图:
但正如你所看到的情节并不突出每个特定clusters.So的中心,有什么办法我可以使用情节R来实现这一点。
当我运行kmeans_output $中心,我得到每个群集的值,但我怎么能在图中显示。 谢谢提前寻求帮助。