How do I label the points in a multidimensional scaling plot?

4 ビュー (過去 30 日間)
Stephen
Stephen 2024 年 6 月 6 日
コメント済み: Andres Adam 2024 年 6 月 6 日
I am studying how to do multidimensional scaling in matlab. I am able to reproduce the output (2D plot) from a published example (http://www.sthda.com/english/articles/31-principal-component-methods-in-r-practical-guide/122-multidimensional-scaling-essentials-algorithms-and-r-code/).
The output is based on the data table found in the Swiss Fertility and Socioeconomic Indicators (1888) (https://rpubs.com/krishnakuyate/Swiss_FS_Data).
I constructed a 47x47 array of Euclidean distances (D) of the Swiss Fertility and Socioeconomic Indicators and ran Y=cmdscale(D,2) to obtain a plot of these data:
But how can I get matlab to label the points in my plot as is done above in the published figure?

採用された回答

Andres Adam
Andres Adam 2024 年 6 月 6 日
Hi Stephen, check out the first example in the documentation of cmdscale:
There is no direct option in cmdscale to add text, but we can do so by using the function text, with the point coordinates offset by a little bit, and a cell array of names:
plot(Y(:,1),Y(:,2),'o') % Your plot
text(Y(:,1)+25,Y(:,2),names)
where the variable names is something like
>> names = {'Herens', 'Sierre', 'Conthey', ... }; (in the appropriate order!)
  2 件のコメント
Stephen
Stephen 2024 年 6 月 6 日
Thanks Andres! Yes, that works but I came across a workaround that is a bit easier for me. Namely, I create a cell array "names" with names copy/pasted from the parent data table:
names=cell(n,1) % n = number of names
Then after I generate the multidimensional scalng 2D plot I run
gname(names);
This allows me to place names on indivividual data points by moving the "crosshairs" that appear on the plot ofer that data point and clicking.
I'll try working with both methods to see which is faster for me.
Andres Adam
Andres Adam 2024 年 6 月 6 日
I did not know that feature! Thanks for pointing it out, and be careful to not confuse points when labeling manually :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by