フィルターのクリア

Scattered plot for different groups of data, subplot?

9 ビュー (過去 30 日間)
wesleynotwise
wesleynotwise 2017 年 5 月 29 日
編集済み: Walter Roberson 2017 年 5 月 30 日
Let say I have a table which contains three columns, Country (4 countries), Variable x and Response y. I would like to know how to create a plot for each country in a single figure?
gscatter (Table.x, Table.y, Table.Country) %This only allows me to plot all four in one graph.

採用された回答

Walter Roberson
Walter Roberson 2017 年 5 月 29 日
[u_country, ~, idx] = unique(Table.Country);
for K = 1 : 4
subplot(2,2,K)
mask = idx == K;
gscatter(Table.x(mask), Table.y(mask), Table.Country(mask));
title( u_country ); %you might need to adjust this depending on the class() of your country data
end
  4 件のコメント
wesleynotwise
wesleynotwise 2017 年 5 月 30 日
編集済み: wesleynotwise 2017 年 5 月 30 日
Thank you! Beautiful plots have been created. I made a minor correction "f2 = gscatter" to my code.
The legend contains the name of lineAtX (this is just a horizontal line I created for the plot to show the neutral axis where y = 0), and I want to exclude it. Can you please show me how this can be done?
Also, is it possible to change the order they appear in the plot? At the moment, the default setting is in alphabetical order.
Walter Roberson
Walter Roberson 2017 年 5 月 30 日
編集済み: Walter Roberson 2017 年 5 月 30 日
If you want to change the order that the countries appear, then you can use
display_order = [2 4 3 1]; %for example
and
% This is Figure 2
figure(2)
[u_country, ~, idx] = unique(Table.Country);
for K = 1 : 4
subplot(2,2,K)
this_country = display_style(K);
mask = idx == this_country;
gscatter(Table.x(mask), Table.y(mask), Table.Country(mask));
hold on
m = 20:10:120; n = 0*m;
lineAtX = plot (m,n, 'k', 'Linewidth', 1.75)
hold off
title( char(u_country(this_country)) );
end

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by