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 $中心,我得到每個羣集的值,但我怎麼能在圖中顯示。 謝謝提前尋求幫助。