1
$\begingroup$

I go straight to the subject; I have the following data set:

datarecords = {{"Industry 4", 158, 64.4}, {"Industry 8", 137, 
    64.4}, {"Industry 5", 141, 62.8}, {"Industry 1", 235, 
    71.1}, {"Industry 3", 225, 71.4}, {"Industry 7", 168, 
    62.}, {"Industry 2", 243, 70.9}, {"Industry 6", 225, 71.4}};

Isolate the values from the names:

datarecordvalues = {#[[2]], #[[3]]} & /@ datarecords

Plot the data values:

plt1 = ListPlot[Tooltip[datarecordvalues]]

Divide the data into two clusters:

c1 = FindClusters[datarecordvalues, 2]

Plot the two clusters:

plt2 = ListPlot[Tooltip[cl]]

Notice that the second plot depicting the two clusters {{158, 64.4}, {137, 64.4}, {141, 62.8}, {168, 62.}} and {{235, 71.1}, {225, 71.4}, {243, 70.9}, {225, 71.4}}] is not correct.

The second plot should be similar to the first plot (except that the points should be visible and the clusters should appear in two different colors).

But the real question that I want to bring on is this:

How can I incorporate the industry labels into the "cluster plot" (i.e.; the second plot); so that these labels appear adjacent to their corresponding points? For instance; if I use Tooltip, and hover my mouse's cursor over the point {137, 64.4}, it should show "Industry 8" as the industry associated with this point. Thank you!

$\endgroup$
2
$\begingroup$

First question

You have to apply Tooltip at the appropriate level.

plt2 = ListPlot[Map[Tooltip[#] &, c1, {2}]]

img]

Second question

Use Association with FindClusters.

aDataRecords = 
 Association[#[[1]] -> #[[2 ;; 3]] & /@ datarecords]

(* <|"Industry 4" -> {158, 64.4}, "Industry 8" -> {137, 64.4}, 
 "Industry 5" -> {141, 62.8}, "Industry 1" -> {235, 71.1}, 
 "Industry 3" -> {225, 71.4}, "Industry 7" -> {168, 62.}, 
 "Industry 2" -> {243, 70.9}, "Industry 6" -> {225, 71.4}|> *)

cls = FindClusters[aDataRecords]

(* {{"Industry 4", "Industry 8", "Industry 5", 
  "Industry 7"}, {"Industry 1", "Industry 3", "Industry 2", 
  "Industry 6"}} *)

ListPlot[
 Map[Tooltip @@@ Transpose[{aDataRecords /@ #, #}] &, cls]]

enter image description here

ListPlot[Map[Tooltip@*aDataRecords /@ # &, cls]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you @Anton Antonov ! I accept your answer! $\endgroup$ Sep 6 '19 at 18:36
  • $\begingroup$ @GilmarRodriguezPierluissi No problem, good luck! $\endgroup$ Sep 6 '19 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.